<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title></title>
	<link rel="stylesheet" href="<%=path %>/automation/css/font.css" />
	<link rel="stylesheet" href="<%=path %>/automation/css/tookPage.css" />
	<link rel="stylesheet" href="<%=path %>/automation/css/region.css" />
	<link rel="stylesheet" href="<%=path %>/automation/plugins/iziModal/iziModal.css" />
			<link rel="stylesheet" href="<%=path %>/css/mushroom.css" />
	 <style type="text/css">
	#store_trade_goods{
	    margin-top: -40px;
	    }
    .search {
        width: 247px;
        height: 36px;
        line-height:36px;
        border: 1px solid #e5e6e7;
        outline:none;
        font-size:14px;
        color:#999999;
        text-indent:10px;
        float:left;
    }

    .searchbg {
        width: 500px;
        margin: 50px auto;
        border:1px solid #e4e4e4;
        padding:10px;
        height:1000px;
    }

    .sure {
        width:70px;
        height:40px;
        line-height: 38px;
        text-indent:20px;
        background:url('<%=path%>/images/automation/buttonbg.png') no-repeat;
        border: none;
       font-size:14px;
       color:#ffffff;
       float:left;
       outline:none;
    }
.table-list {
        width: 100%;
        margin-top: 10px;
        border: 1px solid #e8e8e8;
        border-bottom: none;
    }

    .table-list td {

        border-right: 1px solid #e7e7e7;
    }

    .table-list th {
        border-right: 1px solid #e7e7e7;
        font-weight: normal!important;
    }

    .table-list th td {
        font-size: 14px;
        color: #333333;
        font-weight: normal!important;
    }

    .table-list tbody td {
        text-align: justify;
        font-size: 14px;
        padding: 15px 1px;
        border-bottom: 1px solid #e8e8e8;
    }

    .table-list {
        display: none;
    }

    .table-list thead tr {
        background: #f3f7fa;
        height: 50px;
    }

    .table-list tbody tr {
        cursor: pointer;
    }

    .table-list tbody tr.active {
        background: #f9f9f9;
    }

    .tablelist {
        width: 100%;
        margin-top: 10px;
        border: 1px solid #e8e8e8;
        border-bottom: none;
        position: absolute;
        left: 0px;
        display: none;
        background:#ffffff;
        z-index:20000;
    }

    .tablelist td {
        border-right: 1px solid #e7e7e7;
    }

    .tablelist th {
        border-right: 1px solid #e7e7e7;
        font-weight: normal!important;
        text-align: center;
    }

    .tablelist th td {
        font-size: 14px;
        color: #333333;
        font-weight: normal!important;
    }

    .tablelist tbody td {
        text-align: justify;
        font-size: 14px;
        padding: 15px 1px;
        border-bottom: 1px solid #e8e8e8;
    }

    .tablelist thead tr {
        background: #f3f7fa;
        height: 50px;
    }

    .tablelist tbody tr {
        cursor: pointer;
    }

    .tablelist tbody tr.active {
        background: #f9f9f9;
    }

    .choicebg span {
        display: inline-block;
        border: 1px dashed #d5d5d5;
        padding: 15px 10px;
        margin: 20px 20px 0 0;
        font-size: 16px;
        color: #666666;
        text-align: left;
    }

    .close {
        display: inline-block;
        position: absolute;
        top: -20px;
        right: -20px;
        color: #56B28F;
        font-weight: bold;
        font-size: 16px;
        cursor: pointer;
    }

    .choicebg {
        display: none;
    }
    /* 清除浮动 */

    .clearfix {
        *zoom: 1;
        /*IE/7/6*/
    }

    .clearfix:after {
        content: "\200B";
        display: block;
        height: 0;
        clear: both;
    }

    .choicebg span:hover {
        background: #eeeeee;
    }

    .upperDetail {
        position: absolute;
        top: 0;
        left: 5px;
        width: 480px;
    }

    .search-bg {
        position: relative;
        width: 100%;
        height: 100%;
    }

    .detail-bg {
        position: absolute;
        top: 200px;
        left: 10px;
        /* display: none; */
    }

    .closebg {
        width: 100%;
        height: 100%;
        position: relative;
        cursor: pointer;
    }
    .choicebg2 span {
        display: inline-block;
        border: 1px dashed #d5d5d5;
        padding: 15px 10px;
        margin: 20px 20px 0 0;
        font-size: 16px;
        color: #666666;
        text-align: left;
    }

    .close {
        display: inline-block;
        position: absolute;
        top: -20px;
        right: -20px;
        color: #56B28F;
        font-weight: bold;
        font-size: 16px;
        cursor: pointer;
    }
    .choicebg2 span:hover {
        background: #eeeeee;
    }
    .tablelist3 {
        width: 100%;
        margin-top: 10px;
        border: 1px solid #e8e8e8;
        border-bottom: none;
        position:absolute;
        left:0px;
        background:#ffffff;
        z-index:2000;
    }

    .tablelist3 td {
        border-right: 1px solid #e7e7e7;
    }

    .tablelist3 th {
        border-right: 1px solid #e7e7e7;
        font-weight: normal!important;
        text-align: center;
    }

    .tablelist3 th td {
        font-size: 14px;
        color: #333333;
        font-weight: normal!important;
    }

    .tablelist3 tbody td {
        text-align: justify;
        font-size: 14px;
        padding: 15px 1px;
        border-bottom: 1px solid #e8e8e8;
    }

    .tablelist3 {
       display: none;
    }

    .tablelist3 thead tr {
        background: #f3f7fa;
        height: 50px;
    }

    .tablelist3 tbody tr {
        cursor: pointer;
    }

    .tablelist3 tbody tr.active {
        background: #f9f9f9;
    }
    
    </style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/bootcdn/BootCDN/ajax/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
	<script type="text/javascript" src="<%=path %>/automation/plugins/iziModal/iziModal.js" ></script>
	<script type="text/javascript" src="<%=path %>/automation/plugins/datepicker/WdatePicker.js" ></script>
	<script type="text/javascript" src="<%=path %>/automation/js/balloonSpot.js" ></script>
		<script src="<%=path %>/js/loading.js"></script>
	
</head>
<body>
	<div class="took-panel">
		<div class="took-head">
			<label id="create" class="block-buttons icon-plus master-green freeze-left">创建新模板</label>
			<label id="functions" style="display: none;">
				<span id="moduleName"></span><span id="quickEdit" class="icon-edit smart-edit"></span>
				<input type="hidden" class="line-trip-input" id="moduleNameText" /><span id="quickSave" class="icon-check-avena-o smart-green" style="display:none;"></span>
			</label>
			<label id="save"  class="block-buttons master-green" style="display: none;">保存模板</label>
		</div>
		<div class="took-canvas">
			<div class="start-block" style="display: none;">
				<div class="start-balloon"><label></label></div>
				<div class="start-spot" data-index="1" style="display: none;"><label >条件</label></div>
				<div class="start-spot" data-index="2" style="display: none;"><label>时间</label></div>
				<div class="start-spot" data-index="3" style="display: none;"><label>动作</label></div>
			</div>
		</div>
		<div class="took-layers" style="display: none;">
			<div data-index="1" style="display: none;">
				<div class="layers-top">
					<label class="stripper "></label>
					<label class="head-text"><span>条件设置</span></label>
				</div>
				<div class="layer-content">
					<div class="layer-block" data-action="1">
						<div class="layer-block-head"><label>分组选人</label><label class="group-check icon-toggle-off coat-gray" id="memberShow"></label></div>
						<div class="layer-block-content" style="display: none;">
							<div>
								<div class="coat-head">
									<label class="coat-head-input"><input id="memberGroupName" /></label><label class="coat-head-button"><span class="icon-search" id="memberGroupSearch">搜索</span></label>
								</div>
								<div class="coat-sec">
									<label><span class="check-all symbol-check"></span></label><label><span>全选</span></label>
								</div>
								<div class="coat-content" id="memberGroup">
									<ul>
										<li class="coat-natty"><label><span class="check-natty symbol-check"></span></label><label><span>大众会员</span><span>(2万人)</span></label></li>
										<li class="coat-natty"><label><span class="check-natty symbol-check"></span></label><label><span>特别会员</span><span>(200人)</span></label></li>
										<li class="coat-natty"><label><span class="check-natty symbol-check"></span></label><label><span>高价值</span><span>(500人)</span></label></li>
										<li class="coat-natty"><label><span class="check-natty symbol-check"></span></label><label><span>维护</span><span>(800人)</span></label></li>
										<li class="coat-natty"><label><span class="check-natty symbol-check"></span></label><label><span>一般</span><span>(1000人)</span></label></li>
									</ul>
								</div>
							</div>
						</div>
					</div>
					<div class="layer-block" data-action="2">
						<div class="layer-block-head"><label>条件选人</label><label class="group-check icon-toggle-off coat-gray" id="ruleShow"></label></div>
						<div class="layer-block-content" style="display: none;">
							<div>
								<div class="coat-line">
									<div>
										<label>性别</label>
									</div>
									<div id="gender">
										<span class="checker icon-circle-o" data-group="gender" data-value="m"></span><span class="texter line-sep-natty">男</span>
										<span class="checker icon-circle-o" data-group="gender" data-value="f"></span><span class="texter line-sep-natty">女</span>
										<span class="checker icon-circle-o" data-group="gender" data-value="u"></span><span class="texter">未知</span>
									</div>
								</div>
								<div class="coat-line">
									<div>
										<label>年龄</label>
									</div>
									<div>
										<input class="line-input" maxlength="2" id="startAge" onkeyup="value=value.replace(/[^\d]/g,'')"/><span class="line-sep">至</span><input class="line-input" maxlength="3" id="endAge" onkeyup="value=value.replace(/[^\d]/g,'')"/><span class="line-sep">岁</span>
									</div>
								</div>
								<div class="coat-line">
									<div style="vertical-align:top; padding-top: 8px;">
										<label style="vertical-align:top;">地区</label>
									</div>
									<div style="vertical-align:top;">
										<select class="line-select" style="vertical-align:top;" id="cityType">
											<option value="all">全选</option>
											<option value="include">包括</option>
											<option value="remove">排除</option>
										</select>
										<label class="heart-region" id="regions" data-index="1">
											<span class="show-text" id="cityInfo"></span>
											<span class="sel-btn icon-plus-circle"></span>
											<input type="hidden" data-region-id="1"  />
											<input type="hidden" data-region-pid="1"  />
										</label>
									</div>
								</div>
								<div class="coat-line hold-top">
									<div>
										<label>会员状态</label>
									</div>
									<div>
										<div class="coat-inner-line" id="pre">
											<select class="line-select" data-tag="status" data-team="1" id="preAction">
												<option value="">全部</option>
												<option value="CREATE_CUSTOMER" data-label="1">创建会员</option>
												<option value="BUY_PRICE" data-label="2">购物消费</option>
<!-- 												<option value="BALANCE" data-label="3">会员储值</option>  
 -->												<option value="NO_PRICE" data-label="4">未消费</option>
											</select>
											<div class="hot-box">
												<label class="boxer icon-square-o"></label>
												<label class="starry-natty disable-starry"><input class="line-natty-input" disabled="disabled"  id="preDateInfo"/><span class="starry-natty-sep">天</span></label>
												<select class="line-select" disabled="disabled" id="preDateType">
													<option value="">无</option>
													<option value="BEFORE">以前</option>
													<option value="INNER">以内</option>
												</select>
											</div>
										</div>
										<div class="coat-inner-line">
											<select class="line-select" disabled="disabled" data-tag="rfm" data-team="1" id="preStatus">
												<option value="">不选</option>
												<option value="BUY_NUMBER" data-label="1">购买次数</option>
												<option value="BUY_PRICE" data-label="2">购买金额</option>
												<option value="AVG_PRICE" data-label="3">平均消费</option>
												<option value="MAX_PRICE" data-label="4">最高消费</option>
<!-- 												<option value="BALANCE" data-label="5">储值金额</option>
 -->											</select>
											<input class="line-input fill-left" disabled="disabled" data-team="1" id="preStart" onkeyup="value=value.replace(/[^\d]/g,'')"/><span class="line-sep">至</span>
											<input class="line-input" disabled="disabled" data-team="1" id="preEnd" onkeyup="value=value.replace(/[^\d]/g,'')"/>
										</div>
										<div class="coat-inner-line">
											<select class="line-full-select" data-tag="logic" id="relation">
												<option value="">不选</option>
												<option value="and">并且</option>
												<option value="or">或者</option>
												<option value="not">不是</option>
											</select>
										</div>
										<div class="coat-inner-line" id="pos">
											<select class="line-select" disabled="disabled" data-tag="status" data-team="2" id="posAction">
												<option value="">全部</option>
												<option value="CREATE_CUSTOMER" data-label="1">创建会员</option>
												<option value="BUY_PRICE" data-label="2">购物消费</option>
<!-- 												<option value="BALANCE" data-label="3">会员储值</option>  
 -->												<option value="NO_PRICE" data-label="4">未消费</option>
											</select>
											<div class="hot-box">
												<label class="boxer icon-square-o"></label>
												<label class="starry-natty disable-starry"><input class="line-natty-input" onkeyup="value=value.replace(/[^\d]/g,'')" disabled="disabled"  id="posDateInfo"/><span class="starry-natty-sep">天</span></label>
												<select class="line-select" disabled="disabled" id="posDateType">
													<option value="">无</option>
													<option value="BEFORE">以前</option>
													<option value="INNER">以内</option>
												</select>
											</div>
										</div>
										<div class="coat-inner-line">
											<select class="line-select" disabled="disabled" data-tag="rfm" data-team="2" id="posStatus">
												<option value="">不选</option>
												<option value="BUY_NUMBER" data-label="1">购买次数</option>
												<option value="BUY_PRICE" data-label="2">购买金额</option>
												<option value="AVG_PRICE" data-label="3">平均消费</option>
												<option value="MAX_PRICE" data-label="4">最高消费</option>
<!-- 												<option value="BALANCE" data-label="5">储值金额</option>
 -->											</select>
											<input class="line-input fill-left" disabled="disabled" data-team="2"  onkeyup="value=value.replace(/[^\d]/g,'')" id="posStart"/><span class="line-sep">至</span>
											<input class="line-input" disabled="disabled" data-team="2" id="posEnd" onkeyup="value=value.replace(/[^\d]/g,'')"/>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
					<div  class="layer-block" data-action="3">
						<div class="layer-block-head"><label>行为选人</label><label class="group-check icon-toggle-off coat-gray" id="customerActionShow"></label></div>
						<div class="layer-block-content" style="display: none;">
							<div>
								<div class="coat-line" id="action">
									<span class="checker icon-circle-o" data-group="act" data-value="CHANGE"></span><span class="texter line-sep-natty">提表用户</span>
									<span class="checker icon-circle-o" data-group="act" data-value="NO_CANCEL"></span><span class="texter line-sep-natty" >未核销</span>
									<span class="checker icon-circle-o" data-group="act" data-value="CANCEL"></span><span class="texter">已核销</span>
								</div>
							</div>
						</div>
					</div>
					<div class="layer-block" data-action="4">
						<div class="layer-block-head"><label>触发条件选人</label><label class="group-check icon-toggle-off coat-gray" id="tiggerShow"></label></div>
						<div class="layer-block-content" style="display: none;">
							<div>
								<div class="coat-line hold-top">
									<div>
										<label>用户行为</label>
									</div>
									<div>
										<div class="coat-inner-line">
											<select class="line-select" data-sel="act" id="customerAction">
												<option value="">未指定</option>
												<option value="CREATE_CUSTOMER" data-ref="1">新建会员</option>
												<option value="BUY" data-ref="2">购物消费</option>
<!-- 												<option value="BALANCE" data-ref="3">会员充值</option>
 -->												<option value="BIRTHDAY" data-ref="4">会员生日</option>
												<option value="COUPON_CANCEL" data-ref="5">卡券核销</option>
											</select>
										</div>
										<div class="coat-inner-line" data-sel="act" data-ref="4" style="display: none;">
											<span>前</span><input  class="line-input floor-left" onkeyup="value=value.replace(/[^\d]/g,'')" id="birthdayInfo"/><span class="floor-left">天</span>
										</div>
										<div class="coat-inner-line" data-sel="act" data-ref="2" style="display: none;">
											<select class="line-select" data-sel="able"id="buyInfo">
												<option value="">全选</option>
												<option value="BUY_GOODS" data-ref="1">购买种类</option>
												<option value="BUY_BALANCE" data-ref="2">购买金额</option>
											</select>
											<div class="inner-line-natty" data-sel="able" data-ref="1" style="display: none;"><input  class="line-long-input" id="goodsName" placeholder="请输入商品关键字" /></div>
											<div class="inner-line-natty" data-sel="able" data-ref="2" style="display: none;"><span class="line-sep">满</span><input  onkeyup="value=value.replace(/[^\d]/g,'')" id="priceInfo"class="line-input" /><span class="floor-left">元</span></div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>		
					<div class="layer-block" data-action="5" id="store_trade_info" style="display:none;">
						<div class="layer-block-head"><label>按照门店交易选人</label><label class="group-check icon-toggle-off coat-gray"></label></div>
						<div class="layer-block-content" style="display: none;">
							<div class="coat-line hold-top">
								<li class="coat-natty" style="width:200px;list-style-type:none;"><label><span class="check-natty symbol-check"></span></label><label><span>按购买商品</span></label></li>
							</div>
							<div id="store_trade_goods" style="display:none;">
								<div class="searchbg">
							         <div class="select-bg clearfix">
							            <input class="search" placeholder="请在这里输入药品名称或者商品编码">
							            <input type="button" class="sure" value="确认">
							        </div>
							            <div class="choicebg">
							            </div>
							            <table cellspacing="0" class="table-list">
							                <thead>
							                    <tr>
							                        <th>商品名</th>
							                        <th>通用名</th>
							                        <th>规格</th>
							                        <th width="80px">生产厂商</th>
							                        <th>批准文号</th>
							                        <th>编码</th>
							                    </tr>
							                </thead>
							                <tbody>
							                </tbody>
							            </table>
							        </div>
							</div>
						</div>
					</div>			
				</div>
				<div class="layer-button">
					<label data-index="1" data-tag="confirm" id="ruleCommit" >确定</label>
				</div>
			</div>
			<div data-index="2" style="display: none;">
				<div class="layers-top">
					<label class="stripper "></label>
					<label class="head-text"><span>时间设置</span></label>
				</div>
				<div class="layer-content" id="dateInfo">
					<div class="layer-block">
						<div class="layer-block-head"><label>设置时间</label></div>
						<div class="layer-block-content">
							<div>
								<div class="coat-line">
									<span class="grabber icon-circle-o" data-group="time" data-value="NOW"></span>
									<label>立即执行</label>
								</div>
								<div class="coat-line">
									<span class="grabber icon-circle-o" data-group="time" data-value="AFTER"></span>
									<label class="comm-natty">倒计时时间</label>
									<input class="line-input" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"
									onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'0')}else{this.value=this.value.replace(/\D/g,'')}" disabled="disabled" id="afterInfo" /><span class="line-sep">天之后</span>
								</div>
								<div class="coat-line">
									<span class="grabber icon-circle-o" data-group="time" data-value="CUSTOM"></span>
									<label class="comm-natty">自定义日期</label>
									<input class="line-clock-input" readonly onclick="WdatePicker({minDate:'%y-%M-%d %H',dateFmt:'yyyy-MM-dd HH'})" disabled="disabled" id="customInfo"/>
								</div>
								<div class="coat-line" style="display:none;">
									<span style="float: left;padding-top: 16.5px;" class="grabber icon-circle-o" data-group="time" data-value="USE_DATE"></span>
									<label style="float: left;padding-top: 16.5px;" class="comm-natty">使用时间</label>
									<div style="height:100px;" id="use_date">
										<div class="coat-line">
											<span class="grabber icon-circle-o" data-group="user_time" data-value="USE_AFTER"></span>
											<label class="comm-natty">使用完后</label>
											<input class="line-input" onkeyup="value=value.replace(/[^\d]/g,'')" disabled="disabled" id="use_after_info" /><span class="line-sep">天</span>
										</div>
										<div class="coat-line">
											<span class="grabber icon-circle-o" data-group="user_time" data-value="USE_BEFORE"></span>
											<label class="comm-natty">使用完前</label>
											<input class="line-input" onkeyup="value=value.replace(/[^\d]/g,'')" disabled="disabled" id="use_before_info" /><span class="line-sep">天</span>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
				<div class="layer-button">
					<label data-index="2" data-tag="confirm" id="dateCommit">确定</label>
				</div>
			</div>
			<div data-index="3" style="display: none;">
				<div class="layers-top">
					<label class="stripper "></label>
					<label class="head-text"><span>动作设置</span></label>
				</div>
				<div class="layer-content">
					<div class="layer-block">
						<div class="layer-block-head"><label>营销分类</label></div>
						<div class="layer-block-content">
							<div>
								<div class="coat-line">
									<div>
										<label>发送方式</label>
									</div>
									<div>
										<select class="line-select" id="actionType">
											<option value="">无</option>
											<option value="SMS">短信营销</option>
											<option value="COUPON">优惠券</option>
											<option value="MEDICINE" style="display:none;">医药行业</option>
										</select>
										<span id="actionId" style="display:none;"></span>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
				<div class="layer-button">
					<label data-index="3" data-tag="confirm" id="actionCommit">确定</label>
				</div>
			</div>
		</div>
	</div>
	<div id="module-block"></div>
	<div id="info-block"></div>
	<div id="timer-block"></div>
	<div id="alert-block"></div>
	<div id="alert-block-long"></div>
	<div id="module-sms"></div>
	<div id="module-coupon"></div><div id="module-medicine"></div>
	<input type="hidden" value="<%=path %>/automation/" id="path" />
	<script type="text/javascript" src="<%=path %>/automation/js/region.js" ></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script type="text/javascript" src="<%=path%>/js/marketing/public.js"></script>
</body>
<script>
	var templateId=getQueryString("templateId");
	var templateName;
	var cid=1;
	var taskId;
	var pointId;
	//动作参数
	var actionParams="";
	//动作类型
	var actionTypeInfo;
	var path = "<%=path%>";
	//判断是否提交表单
	var flag=true;
	var commitIndex;
	var commitType;
	var commitData;
	var commitParentId;
	//初始化画图方法
	function init(){
		//初始化数据到临时表
		initTempData(templateId);
		findTemplateInfo(templateId);
		selectPointByTemplateId(templateId);
		findMax(templateId);
	}
	function initTempData(id){
		var url=path+"/autoMarketTempPoint/insertTempPointFromPoint";
		$.ajax({
 			type:"post",
 			url:url,
  			async: false,
  			data:{"cid" : cid,
            	"templateId":id
            	},success:function(data){
				if(data.status==200){
					
				}else{
					showError(data.message);
				}}
		});
	}
	//查询模板下所有节点信息
	function selectPointByTemplateId(id){
		var url=path+"/autoMarketTempPoint/findTempPointListByDto";
		$.ajax({
 			type:"post",
 			url:url,
  			async: false,
  			data:{"cid" : cid,
            	"templateId":id
            	},success:function(data){
				if(data.status==200){
					loadItems(data.data);
				}else{
					showError(data.message);
				}}
		});
	}
	function loadItems(list){
		$("#moduleName").text(templateName); 
		$("#moduleNameText").val(templateName);
		$("#module-block").iziModal('close');						
		$("#create").hide();
		$("#functions").show();
		$("#save").show();
		for(var i=0;i<list.length;i++){
				createSpot({
					sn: list[i].id,
					type: list[i].type,
					from: list[i].parentId
				});
			if(i!=0){
				drawLine({
					from: list[i].parentId,
					to: list[i].id
				});		
			}			
		}
	}

	$(function(){
		init();
		$("#module-block").iziModal({
	        title: "创建新模板",
	        width: 600,
	        zindex: 101
	    });
	    $("#info-block").iziModal({
	        title: "消息",
	        width: 660,
	        zindex: 101
	    });
		
		$("#timer-block").iziModal({
	        title: "设置时间",
	        width: 300,
	        zindex: 101
	    });
	    
	    $("#alert-block").iziModal({
	        title: "提示",
	        width: 300,
	        zindex: 101
	    });
	    $("#alert-block-long").iziModal({
	        title: "提示",
	        width: 400,
	        zindex: 101
	    });
		// the start spot with a big "+"
		$(".start-balloon").on("click", function(){
			var $cur = $(this);
			var index = 1;
			$(".took-layers").show();
			$(".took-layers").find("div[data-index='"+index+"']").show();
			$(".took-layers").find("div[data-index='"+index+"']").find(":input").val("");
			$(".start-block").hide();
			$(".took-head").css("right", "41%");
			$(".took-canvas").css("right", "41%");
			
			$(".took-layers").find("div.layer-block[data-action='3']").hide();
			
		});
		
		// the toggle button
		$(".took-panel").off("click", ".group-check");
		$(".took-panel").on("click", ".group-check", function(){
			var $cur = $(this);
			var $block = $cur.parents(".layer-block-head").next(".layer-block-content");
			if($block.css("display") == "none") {
				$cur.removeClass("icon-toggle-off").removeClass("coat-gray").addClass("coat-green").addClass("icon-toggle-on");
				$block.slideDown().scrollTop(0);
			} else {
				$cur.removeClass("icon-toggle-on").removeClass("coat-green").addClass("coat-gray").addClass("icon-toggle-off");
				$block.hide();
			}
		});
		
		// "checkbox" in the 'select people with group'
		$(".took-panel").off("click", ".check-natty");
		$(".took-panel").on("click", ".check-natty", function(){
			var $cur = $(this);
			var $li = $cur.parents("li");
			if($li.hasClass("active-natty")) {
				$li.removeClass("active-natty");
			} else {
				$li.addClass("active-natty");
			}
		});
		
		// "all-check" in the 'select people with group'
		$(".took-panel").off("click", ".check-all");
		$(".took-panel").on("click", ".check-all", function(){
			var $cur = $(this);
			if($cur.hasClass("active-natty-all")) {
				$cur.removeClass("active-natty-all");
				$(".coat-natty").removeClass("active-natty");
			} else {
				$cur.addClass("active-natty-all");
				$(".coat-natty").addClass("active-natty");
			}
		});
		
		// "radio" in the 'select people with condition'
		$(".took-panel").off("click", ".checker");
		$(".took-panel").on("click", ".checker", function(){
			var $cur = $(this);
			if($cur.hasClass("icon-circle-o")) {
				$cur.removeClass("icon-circle-o").addClass("icon-check-circle-o").addClass("coat-green");
				$cur.siblings("[data-group]").removeClass("coat-green").removeClass("icon-check-circle-o").addClass("icon-circle-o");
			} else if($cur.hasClass("icon-check-circle-o")) {
				$cur.removeClass("coat-green").removeClass("icon-check-circle-o").addClass("icon-circle-o");
			}
		});
		$(".took-panel").off("click", ".texter");
		$(".took-panel").on("click", ".texter", function(){
			var $cur = $(this).prev();
			if($cur.hasClass("icon-circle-o")) {
				$cur.removeClass("icon-circle-o").addClass("icon-check-circle-o").addClass("coat-green");
				$cur.siblings("[data-group]").removeClass("coat-green").removeClass("icon-check-circle-o").addClass("icon-circle-o");
			} else if($cur.hasClass("icon-check-circle-o")) {
				$cur.removeClass("coat-green").removeClass("icon-check-circle-o").addClass("icon-circle-o");
			}
		});
		
		// "checkbox" in the 'select people with condition'
		$(".took-panel").off("click", ".boxer");
		$(".took-panel").on("click", ".boxer", function(){
			var $cur = $(this);
			var $label = $cur.next();
			var $select = $label.next();
			if($cur.hasClass("icon-square-o")) {
				$cur.removeClass("icon-square-o").addClass("coat-green").addClass("icon-check-square");
				$label.removeClass("disable-starry");
				$label.find("input").prop("disabled", false);
				$select.prop("disabled", false);
			} else {
				$cur.removeClass("icon-check-square").removeClass("coat-green").addClass("icon-square-o");
				$label.addClass("disable-starry");
				$label.find("input").prop("disabled", true).val("");
				$select.prop("disabled", true);
			}
		});
		
		// "radio" in the 'select people with action'
		$(".took-panel").off("click", ".grabber");
		$(".took-panel").on("click", ".grabber", function(){
			var $cur = $(this);
			var group = $cur.data("group");
			var $div = $cur.parent().parent();
			$div.find("[data-group='"+group+"']").removeClass("coat-green").removeClass("icon-check-circle-o").addClass("icon-circle-o");
			$cur.removeClass("icon-circle-o").addClass("icon-check-circle-o").addClass("coat-green");
			$cur.parent().find(":input").val("").prop("disabled", false);
			$cur.parent().siblings().find(":input").val("").prop("disabled", true);
		});
		
		// select in the 'select people with trigger'
		$(".took-panel").off("change", "select[data-sel]");
		$(".took-panel").on("change", "select[data-sel]", function(){
			var $cur = $(this);
			var ref = $cur.find("option:selected").data("ref");
			var sel = $cur.data("sel");
			$("div[data-sel='"+sel+"']").hide();
			$("div[data-sel='"+sel+"'][data-ref='"+ref+"']").show();
		});
		
		// select for "member status"
		$(".took-panel").off("change", "select[data-tag]");
		$(".took-panel").on("change", "select[data-tag]", function(){
			var $cur = $(this);
			var val = $cur.val();
			var _tag = $cur.data("tag");
			var team = $cur.data("team");
			if(_tag == "status") {
				$(".took-panel").find("select[data-tag='rfm'][data-team='"+team+"']").val("");
				$(".took-panel").find("input[data-team='"+team+"']").val("").prop("disabled", true);
				if(val == "BUY_PRICE" || val == "BALANCE") {
					$(".took-panel").find("select[data-tag='rfm'][data-team='"+team+"']").prop("disabled", false);
					if(val == "BUY_PRICE") {
						$(".took-panel").find("select[data-tag='rfm'][data-team='"+team+"']").find("option[data-label='5']").prop("disabled", true);
						$(".took-panel").find("select[data-tag='rfm'][data-team='"+team+"']").find("option[data-label!='5']").prop("disabled", false);
						$(".took-panel").find("select[data-tag='rfm'][data-team='"+team+"']").find("option[value='']").prop("disabled", false);
					} else {
						$(".took-panel").find("select[data-tag='rfm'][data-team='"+team+"']").find("option[data-label='5']").prop("disabled", false);
						$(".took-panel").find("select[data-tag='rfm'][data-team='"+team+"']").find("option[data-label!='5']").prop("disabled", true);
						$(".took-panel").find("select[data-tag='rfm'][data-team='"+team+"']").find("option[value='']").prop("disabled", false);
					}
				} else {
					$(".took-panel").find("select[data-tag='rfm'][data-team='"+team+"']").prop("disabled", true);
				}
			} else if(_tag == "rfm") {
				$(".took-panel").find("input[data-team='"+team+"']").val("").prop("disabled", false);
			} else if(_tag == "logic") {
				if(val != "") {
					$(".took-panel").find("select[data-team='2'][data-tag]").prop("disabled", false);
				} else {
					$(".took-panel").find("select[data-team='2'][data-tag]").prop("disabled", true);
				}
			}
		});
		
		// the confirm "button"
		$(".took-panel").off("click", "label[data-tag='confirm']");
		$(".took-panel").on("click", "label[data-tag='confirm']", function(){
				var $cur = $(this);
				var index = $cur.data("index");				
				var flag = true;
				var type=$cur.attr("curType");
				// do validate
				flag = validateInfo(type);
				var validate= type ;
				if(flag){
					//提交信息 
					//1判断插入还是修改
					var update=$cur.attr("update");
					if(update=="1"){
						flag=savePointInfo(commitData,validate,commitParentId);
					}else if(update=="2"){
						flag=updatePointInfo(commitIndex,commitData);
					}
					//判断是否需要添加节点
					if(flag&&update=="1"){
						$(".took-layers").find("div[data-index='"+index+"']").hide();
						$(".took-layers").hide();
						$(".took-head").css("right", 0);
						$(".took-canvas").css("right", 0);
						
						var len = $(".took-canvas").find("div.balloon-spot").length;
						createSpot({
							sn: len + 1,
							type: index,
							from: $cur.attr("index")
						});
						drawLine({
							from: $cur.attr("index"),
							to: len + 1
						});		
					}else if(flag&&update=="2"){
					   $(".took-layers").find("div[data-index='"+index+"']").hide();
						$(".took-layers").hide();
						$(".took-head").css("right", 0);
						$(".took-canvas").css("right", 0);					
				   }
				}				
		});
		
		// open the panel for region.js
		$(".took-panel").off("click", ".sel-btn");
		$(".took-panel").on("click", ".sel-btn", function(){
			var $region = $(this).parent();
			var _id = $region.find("input[data-region-id]").val();
			var _pid = $region.find("input[data-region-pid]").val();
			var _text = $region.find(".show-text").attr("title");
			var items = "";
			if(_id != '') {
				var idArr = _id.split(",");
				var pidArr = _pid.split(",");
				var textArr = _text.split(",");
				
				for(var i=0; i<idArr.length; i++) {
					var c_id = idArr[i];
					var c_pid = pidArr[i];
					var c_text = textArr[i];
					items += "<label class='result-item' data-id='"+c_id+"' data-parent='"+c_pid+"'><span>"+c_text+"</span><span class='icon-remove'></span></label>"
				}
			}
			
			var modal = $('#info-block').iziModal();
			var content = "<div class='city-block'>"
								+ "<div class='result-panel'>"
								+ "<label>已选项</label><input type='hidden' id='sel-city' />" + items
								+ "</div>"
								+ "<div class='data-tabs'>"
								+ "<ul class='natty-tabs'>"
								+ "<li class='active-tab' data-index='1'><label id='extra-boot'><span>全部</span></label></li>"
								+ "<li data-index='2' style='display:none;'><label><span></span></label></li>"
								+ "</ul>"
								+ "<input id='search-city' placeholder='请搜索城市'  />"
								+ "<div class='search-result' style='display:none;'><ul></ul></div>"
								+ "</div>"
								+ "<div class='data-block' data-tab='1'>"
								+ "<h4><label>全部省区</label></h4>"
								+ "<div class='data-info'><ul></ul></div>"
								+ "</div>"
								+ "<div class='data-block' data-tab='2' style='display:none;'>"
								+ "<h4></h4>"
								+ "<div class='data-info'><ul></ul></div>"
								+ "</div>"
								+ "</div>"
								+ "<div class='block-button'>"
								+ "<label class='item-ace bord-green cancel-confirm' style='margin-right:8px;'><span>取消</span></label>"
								+ "<label class='item-ace btn-green do-confirm'><span>确定</span></label>"
								+ "</div>";
			$("#info-block").find(".iziModal-content").html(content);
			modal.iziModal('setTitle', "选择区域");
			modal.iziModal('setHeaderColor', 'rgb(211, 211, 211)');
			loadProvince();	
			setTimeout(function(){
				if(_id != '') {
					repageSelection(_id, _pid);					
				}
				modal.iziModal('open');
			}, 800);
			
		});
		
		// the confirm "button" in the region panel
		$("#info-block").off("click", ".do-confirm");
		$("#info-block").on("click", ".do-confirm", function(){
			var _text = "";
			var _id = "";
			var _parent = "";
			$("#info-block").find(".result-item").each(function(){
				var $cur = $(this);
				var cur_text = $cur.find("span").text();
				_text += "," + cur_text;
				var cur_id = $cur.data("id");
				_id += "," + cur_id;
				var cur_parent = $cur.data("parent");
				_parent += "," + cur_parent;
			});
			_text = _text.startsWith(",") ? _text.substr(1) : _text;
			_id = _id.startsWith(",") ? _id.substr(1) : _id;
			_parent = _parent.startsWith(",") ? _parent.substr(1) : _parent;
			
			var showText = "";
			if(_text.length > 7) {
				showText = _text.substr(0, 6) + "...";
			} else {
				showText = _text;
			}
			
			$("#regions[data-index='1']").find(".show-text").text(showText).attr("title", _text);
			$("#regions[data-index='1']").find("input[data-region-id]").val(_id);
			$("#regions[data-index='1']").find("input[data-region-pid]").val(_parent);
			$("#info-block").iziModal('close');
		});
		
		// the cancel "button" in the region panel
		$("#info-block").off("click", ".cancel-confirm");
		$("#info-block").on("click", ".cancel-confirm", function(){
			$("#info-block").iziModal('close');
		});
		
		// open the panel for creating a module 
		$("#create").click(function(){
			var module = $("#module-block").iziModal();
			var selections = "<label style='margin:0 12px 0 24px;'>请输入模板名称</label><input class='input-extend' />";
			var content = "<div style='padding: 2em 1em;'>" + selections + "</div>";
			var buttons = "<p style='padding:0 1em; text-align:center;'>"
									+ "<label class='item-ace bord-green cancel-confirm' style='margin-right:8px;'><span>取消</span></label>"
									+ "<label class='item-ace btn-green do-confirm'><span>确定</span></label>"
									+ "</p>";
			$("#module-block").find(".iziModal-content").html(content + buttons);
			module.iziModal('setHeaderColor', 'rgb(211, 211, 211)');
			module.iziModal('open');
		});
		
		// the confirm "button" in the creation panel
		$("#module-block").off("click", ".do-confirm");
		$("#module-block").on("click", ".do-confirm", function(){
			var flag=true;
			var val = $("#module-block").find("input").val();
			if(val != '') {
				flag=checkAutomationTemplateByName(val);
				if(flag){
					$("#moduleName").text(val); 
					$("#moduleNameText").val(val);
					$("div.start-block").show();
					$("#module-block").iziModal('close');						
					$("#create").hide();
					$("#functions").show();
					$("#save").show();	
					 var addTemplateUrl=path+"/automarket/addAutoMarketTemplate";
					$.post(addTemplateUrl,{"cid" : cid,
			        	"name":val
					},function(data){
						if(data.status==200){
							templateId=data.data;
							$("#moduleName").text(val); 
							$("#moduleNameText").val(val);
							$("div.start-block").show();
							$("#module-block").iziModal('close');						
							$("#create").hide();
							$("#functions").show();
							$("#save").show();		
						}else{
							showError(data.message);
						}
					});		
				}
				} else {
					showError("未填写模板名称！");
				}
				
		});
		
		// the cancel "button" in the creation panel
		$("#module-block").off("click", ".cancel-confirm");
		$("#module-block").on("click", ".cancel-confirm", function(){
			$("#module-block").iziModal('close');
		});
		
		// the main balloon click, call the panel in the right to edit
		$(".took-canvas").off("click", ".main-balloon>label");
		$(".took-canvas").on("click", ".main-balloon>label", function(){
			var $cur = $(this);
			var $block = $cur.parent().parent();
			$block.find(".s-balloon").hide();
			var cur_type = $block.data("type");
			var index = $block.data("index");
			$(".took-layers").show();
			$(".took-layers").find("div[data-index]").hide();
			
			var $block = $(".took-layers").find("div[data-index='"+cur_type+"']");
			$block.show();
			
			$block.find("input").val("");
			$block.find("select").val("");
			
			$block.find(".checker").removeClass("coat-green").removeClass("icon-check-circle-o").addClass("icon-circle-o");
			$block.find(".grabber").removeClass("coat-green").removeClass("icon-check-circle-o").addClass("icon-circle-o");
			$block.find(".boxer").removeClass("coat-green").removeClass("icon-check-square").addClass("icon-square-o");
			
			if(cur_type == 1) {
				$block.find(".group-check").removeClass("icon-toggle-on").removeClass("coat-green").addClass("icon-toggle-off").addClass("coat-gray");
				
				$block.find(".layer-block-content").hide();
				$block.find(".coat-natty").removeClass("active-natty");
				$block.find(".check-all").removeClass("active-natty-all");
				
				var $panel = $block.find("div.layer-block[data-action='2']");
				$panel.find(".coat-inner-line").find(":input").prop("disabled", true);
				$panel.find(".coat-inner-line").find("select[data-team='1'][data-tag='status']").prop("disabled", false);
				$panel.find(".coat-inner-line").find("select[data-tag='status']").prop("disabled", false);
				$panel.find(".starry-natty").addClass("disable-starry");
				$panel.find(".show-text").empty();
				
				$block.find("div[data-sel='act']").hide();
			} else if(cur_type == 2) {
				$block.find(":input").prop("disabled", true);
			}
			
			if(cur_type=="1"){
				$("#ruleCommit").attr("update",2).attr("curType",1).attr("point",index);
				dataEcho(1,index);
			}else if(cur_type=="2"){
				$("#dateCommit").attr("update",2).attr("curType",2).attr("point",index);
				dataEcho(2,index);
			}else if(cur_type=="3"){
				$("#actionCommit").attr("update",2).attr("curType",3).attr("point",index);
				$("#actionType").attr("disabled","disabled");
				searchActionInfo(index);
				var numbers = $("#actionType").find("option"); 
				if(actionTypeInfo=="SMS"){
					$(numbers[1]).prop("selected","selected");
					var modal = $("#module-sms").iziModal();
					modal.iziModal('setHeaderColor', 'rgb(202,38,0)');
					modal.iziModal('setTitle',"请选择短信模板");
					modal.iziModal('open', {
						iframeURL:path+"/view/automarket/createSms?template_id="+templateId+actionParams
					});
				}else if(actionTypeInfo=="COUPON"){
					$(numbers[2]).prop("selected","selected");
					var modal = $("#module-coupon").iziModal();
					modal.iziModal('setHeaderColor', 'rgb(202,38,0)');
					modal.iziModal('setTitle',"请选择注券模板");
					modal.iziModal('open', {
						iframeURL:path+"/view/automarket/createCouponBatch?template_id="+templateId+actionParams
					});
				}else if(actionTypeInfo=="MEDICINE"){
					$(numbers[3]).prop("selected","selected");
					var modal = $("#module-medicine").iziModal();
					modal.iziModal('setHeaderColor', 'rgb(202,38,0)');
					modal.iziModal('setTitle',"请选择医药行业模板");
					modal.iziModal('open', {
						iframeURL:path+"/view/automarket/modalSmsModelEdit?template_id="+templateId+actionParams
					});
				}
				$("#actionType").trigger("change");
				actionTypeInfo="";
				actionParams="";
			}
			$(".took-head").css("right", "41%");
			$(".took-canvas").css("right", "41%");
			//var index = $block.data("index");
			if(cur_type == '1') {
				if(index == '1') {
					$(".took-layers").find("div.layer-block[data-action='1']").show();
					$(".took-layers").find("div.layer-block[data-action='3']").hide();
				} else {
					$(".took-layers").find("div.layer-block[data-action='1']").hide();
					$(".took-layers").find("div.layer-block[data-action='3']").show();
				}
			}
			if(medicineFlag){
				hideDontMedicineRule();
			}
			if(normalSign){
				initIndustryInfo(null);
			}
		});
		
		// the small balloon click, call the panel in the right to create
		$(".took-canvas").off("click", ".s-balloon>label");
		$(".took-canvas").on("click", ".s-balloon>label", function(){			
			var $cur = $(this);
			var $block = $cur.parent().parent();
			var group = $block.data("group");
			var type = $cur.data("type");
			var tag = $cur.data("tag");
			var index = $block.data("index");
			var flag=true;
			
			if(taskId<20){
				//恢复
				$("#actionType").removeAttr("disabled");
				$("#store_trade_goods li").attr("class","coat-natty");
				$("#store_trade_goods").attr("style","display:none;");
				$(".choicebg").empty();
				//校验
				var validate= type;
				if(StringEmpty(type)){
					flag=validateTypeByParent(index,validate);
				}
				if(flag){
					if(type=="1"){
						$("#ruleCommit").attr("update",1).attr("curType",1);
					}else if(type=="2"){
						$("#dateCommit").attr("update",1).attr("curType",2);
					}else if(type=="3"){
						$("#actionCommit").attr("update",1).attr("curType",3);
					}
					if(tag == "1") {
						callPanel(index, type);
					} else {
						var dataType = $block.data("type");
						var name = dataType == "1" ? "条件" : dataType == "2" ? "时间" : "动作";
						var modal = $("#info-block").iziModal();
						//var info = loadInfo(dataType);
						loadInfoByPoint(index,templateId,dataType);
						//$("#info-block").find(".iziModal-content").html(info);
						modal.iziModal('setHeaderColor', 'rgb(211, 211, 211)');
						modal.iziModal('setTitle', name + "预览");
						modal.iziModal('open');
					}
					$block.find(".s-balloon").hide();
					$block.find(".spot-line").show();
					if(type == "1") {
						$(".took-layers").find("div.layer-block[data-action='1']").hide();
						$(".took-layers").find("div.layer-block[data-action='3']").show();
					}
					if(medicineFlag){
						hideDontMedicineRule();
					}
					if(normalSign){
						initIndustryInfo(null);
					}
				}	
			}else{
				showError("任务不能超过20组！");
			}
		});
		
		// title edit "button"
		$("#quickEdit").click(function(){
			var $cur = $(this);
			$("#moduleNameText").attr("type", "text");
			$("#quickSave").show();
			$("#moduleName").hide();
			$cur.hide();
		});
		// title save "button"
		$("#quickSave").click(function(){
			var $cur = $(this);
			var flag=true;
			var val=$("#moduleNameText").val();
			if(val != '') {
				if(!templateName==val){
					flag=checkAutomationTemplateByName(val);
				}
				if(flag){
					$("#moduleName").text($("#moduleNameText").val()).show();
					$("#quickEdit").show();
					$("#moduleNameText").attr("type", "hidden");
					$cur.hide();
					templateName=val;
				}			
			} else  {
				showError("模板名称不能为空！");
			}
		});
		
		// when mouse is on the main balloon, show hover style and small balloon
		$(".took-canvas").off("mouseover", ".main-balloon>label");
		$(".took-canvas").on("mouseover", ".main-balloon>label", function(){
			var $cur = $(this);
			var $bk = $cur.parent();
			var $block = $bk.parent();
			var type = $block.data("type");
			var keywords = type == "1" ? "-cond" : type == "2" ? "-time" : "-act";
			var cls = "umbrella" + keywords;
			var bk_cls = "umbrella-bk" + keywords;
			if($cur.hasClass(cls)) {
				$cur.removeClass(cls).stop().addClass(cls+"-hover");
				$bk.removeClass(bk_cls).stop().addClass(bk_cls+"-hover");
				
				// close all the spot all the canvas
				$(".took-canvas").find(".s-balloon").hide();
				$(".took-canvas").find(".spot-line").show();
				
				if(type == 1) {
					$block.find(".s-balloon[data-pos='2']").show();
					$block.find(".s-balloon[data-pos='4']").show();
				} else if(type == 2) {
					$block.find(".s-balloon[data-pos='3']").show();
					$block.find(".s-balloon[data-pos='4']").show();
				} else if(type == 3) {
					$block.find(".s-balloon[data-pos='1']").show();
					$block.find(".s-balloon[data-pos='4']").show();
				}
				$block.find(".spot-line").hide();
				// 5 seconds without any actions, do the hide
				setTimeout(function(){
					$block.find(".s-balloon").hide();
					$block.find(".spot-line").show();
				}, 5000);
			}
		});
		
		// when mouse is out of the main balloon, hide hover style
		$(".took-canvas").off("mouseout", ".main-balloon>label");
		$(".took-canvas").on("mouseout", ".main-balloon>label", function(){
			var $cur = $(this);
			var $bk = $cur.parent();
			var $block = $bk.parent();
			var type = $block.data("type");
			var keywords = type == "1" ? "-cond" : type == "2" ? "-time" : "-act";
			var cls = "umbrella" + keywords;
			var bk_cls = "umbrella-bk" + keywords;
			if($cur.hasClass(cls+"-hover")) {
				$cur.removeClass(cls+"-hover").stop().addClass(cls);
				$bk.removeClass(bk_cls+"-hover").stop().addClass(bk_cls);
			}
		});
		
		// when mouse is on the small balloon, show the hove style
		$(".took-canvas").off("mouseover", ".s-balloon>label");
		$(".took-canvas").on("mouseover", ".s-balloon>label", function(){
			var $cur = $(this);
			var tag = $cur.data("tag");
			var fun = tag == "1" ? "plus" : "view";
			var $bk = $cur.parent();
			var $block = $bk.parent();
			var type = $block.data("type");
			var keywords = type == "1" ? "-cond" : type == "2" ? "-time" : "-act";
			var cls = "daisy-" + fun + keywords;
			var bk_cls = "daisy-bk" + keywords;
			if($cur.hasClass(cls)) {
				$cur.removeClass(cls).stop().addClass(cls+"-hover");
				$bk.removeClass(bk_cls).stop().addClass(bk_cls+"-hover");
			}
		});
		
		// when mouse is out of the small balloon, hide hover style
		$(".took-canvas").off("mouseout", ".s-balloon>label");
		$(".took-canvas").on("mouseout", ".s-balloon>label", function(){
			var $cur = $(this);
			var tag = $cur.data("tag");
			var fun = tag == "1" ? "plus" : "view";
			var $bk = $cur.parent();
			var $block = $bk.parent();
			var type = $block.data("type");
			var keywords = type == "1" ? "-cond" : type == "2" ? "-time" : "-act";
			var cls = "daisy-" + fun + keywords;
			var bk_cls = "daisy-bk" + keywords;
			if($cur.hasClass(cls + "-hover")) {
				$cur.removeClass(cls + "-hover").stop().addClass(cls);
				$bk.removeClass(bk_cls + "-hover").stop().addClass(bk_cls);
			}
		});
	});
	
	function callPanel(index, type) {
		$(".took-layers").find("div[data-index]").hide();
		$(".took-layers").show();
		
		var $block = $(".took-layers").find("div[data-index='"+type+"']");
		$block.show();
		
		$block.find("input").val("");
		$block.find("select").val("");
		
		$block.find(".checker").removeClass("coat-green").removeClass("icon-check-circle-o").addClass("icon-circle-o");
		$block.find(".grabber").removeClass("coat-green").removeClass("icon-check-circle-o").addClass("icon-circle-o");
		$block.find(".boxer").removeClass("coat-green").removeClass("icon-check-square").addClass("icon-square-o");
		
		if(type == 1) {
			$block.find(".group-check").removeClass("icon-toggle-on").removeClass("coat-green").addClass("icon-toggle-off").addClass("coat-gray");
			
			$block.find(".layer-block-content").hide();
			$block.find(".coat-natty").removeClass("active-natty");
			$block.find(".check-all").removeClass("active-natty-all");
			
			var $panel = $block.find("div.layer-block[data-action='2']");
			$panel.find(".coat-inner-line").find(":input").prop("disabled", true);
			$panel.find(".coat-inner-line").find("select[data-team='1'][data-tag='status']").prop("disabled", false);
			$panel.find(".coat-inner-line").find("select[data-tag='status']").prop("disabled", false);
			$panel.find(".starry-natty").addClass("disable-starry");
			$panel.find(".show-text").empty();
			
			$block.find("div[data-sel='act']").hide();
		} else if(type == 2) {
			$block.find(":input").prop("disabled", true);
		}
		$block.find("label[data-tag='confirm']").attr("index", index);
		$(".took-head").css("right", "41%");
		$(".took-canvas").css("right", "41%");
	}
	
	function loadInfo(type) {
		var content = "<div style='padding: 1em;'>";
		if(type == "1") {
			content += "<div class='block-inner-line'><div><label>分组选人</label></div><div><label>大众会员（2万人）</label><label>高价值（5000人）</label></div></div>"
							+ "<div class='block-inner-line'><div><label>条件选人</label></div><div><label><span>性别</span><span>男</span></label>"
							+ "<label><span>年龄</span><span>18至24岁</span></label>"
							+ "<label><span>地区</span><span>包括北京、上海、广州</span></label>"
							+ "<label><span>教育水平</span><span>专科至本科</span></label>"
							+ "<label><span>会员等级</span><span>1级至3级</span></label>"
							+ "<label><span>会员状态</span><span>购物消费</span><span>10天以前</span><span>购买次数</span><span>1次至3次</span></label>"
							+ "</div></div>"
							+ "<div class='block-inner-line'><div><label>触发条件选人</label></div><div><label><span>用户行为</span><span>会员充值</span><span>满100元</span></label></div></div>";
		} else if(type =="2") {
			content += "<div class='block-inner-line'><div><label>设置时间</label></div><div><label><span>生日</span><span>前一天</span></label></div></div>";
		} else {
			content += "<div class='block-inner-line'><div><label>名称</label></div><div><label>春季派发</label></div></div>"
							+ "<div class='block-inner-line'><div><label>发送量</label></div><div><label>1000</label></div></div>"
							+ "<div class='block-inner-line'><div><label>到达量</label></div><div><label>8000</label></div></div>"
							+ "<div class='block-inner-line'><div><label>点击量</label></div><div><label>200</label></div></div>"
							+ "<div class='block-inner-line'><div><label>提交表单</label></div><div><label>100</label></div></div>";
		}
		content += "</div>"
		return content;
	}
	function checkPage(index) {
		if(index == "1") {
			var $block = $(".took-layers").find("div[data-index='"+index+"']");
			var val_rfm = $block.find("select[data-tag='status'][data-team='1']").val();
			var val_trigger = $block.find("select[data-sel='act']").val();
			var sel_act = 0;
			$block.find("span.checker").each(function(){
				if($(this).hasClass("icon-check-circle-o")) {
					sel_act++;
				}
			});			
			return true;
		} else {
			return true;
		}
	}
	function showError(info) {
		var modal = $("#alert-block").iziModal();
		modal.iziModal('setHeaderColor', 'rgb(202,38,0)');
		modal.iziModal('setTitle', info);
		modal.iziModal('open');
	}
	 function showErrorLong(info) {
			var modal = $("#alert-block-long").iziModal();
			modal.iziModal('setHeaderColor', 'rgb(202,38,0)');
			modal.iziModal('setTitle', info);
			modal.iziModal('open');
		}
	$("#module-sms").iziModal({
		iframe: true,
	    iframeHeight: 800
	});
	$("#module-coupon").iziModal({
		iframe: true,
	    iframeHeight: 800
	});
	$("#module-medicine").iziModal({
		width: 600,
		iframe: true,
	    iframeHeight: 800
	});
	$("#actionType").change(function (){
		$("#actionId").html(1);
		//校验是否可选
		var type=$("#actionType").val();
		var parentId=$("#actionCommit").attr("index");
		var flag=validateAction(parentId,type);
		if(!flag){
			return null;
		}
		if($("#actionType").val()=="SMS"){
			var modal = $("#module-sms").iziModal();
			modal.iziModal('setHeaderColor', 'rgb(202,38,0)');
			modal.iziModal('setTitle',"请选择短信模板");
			modal.iziModal('open', {
				iframeURL:path+"/view/automarket/createSms?template_id="+templateId+actionParams
			});
		}else if($("#actionType").val()=="COUPON"){
			var modal = $("#module-coupon").iziModal();
			modal.iziModal('setHeaderColor', 'rgb(202,38,0)');
			modal.iziModal('setTitle',"请选择注券模板");
			modal.iziModal('open', {
				iframeURL:path+"/view/automarket/createCouponBatch?template_id="+templateId+actionParams
			});
		}else if($("#actionType").val()=="MEDICINE"){
			var modal = $("#module-medicine").iziModal();
			modal.iziModal('setHeaderColor', 'rgb(202,38,0)');
			modal.iziModal('setTitle',"请选择医药行业模板");
			modal.iziModal('open', {
				iframeURL:path+"/view/automarket/modalSmsModelEdit?template_id="+templateId+actionParams
			});
		}
	})
/*****************************				交互							*****************************/
	var array=new Array();
	$(function(){
		memberGroupInit();
	})	
	$("#memberGroupSearch").click(function(){
		memberGroupInit();
	})
	//分组列表显示
	function memberGroupInit(){		
		var html="";
		var name=$("#memberGroupName").val();
		if(!StringEmpty(name)){
			name=null;
		}
		var findByName=path+"/memberGroup/findMemberGroupByName";
		$.ajax({
	 			type:"post",
	  			url:findByName,
	  			async: false,
	  			data:{"cid" : cid,
	            	"name":name
	            	},success:function(data){
			if(data.status==200){
				var list=data.data;				
				for(var i=0;i<list.length;i++){
					var count=list[i].count;
					if(!StringEmpty(count)){
						count=0;
					}
					html+="<li class='coat-natty'><label><span class='check-natty symbol-check' data-id="+list[i].id+"></span></label><label><span>"+list[i].name+"</span><span>("+count+")人</span></label></li>";
				}
			}}
		});			
		$("#memberGroup>ul").empty().append(html);
	}
	//获取分组信息
	function memberGroupInfo(){
		if($("#memberShow").hasClass("icon-toggle-off")){
			return null;
		}
		var memberArray=new Array();
		var i=0;
		$("#memberGroup .active-natty").each(function(index,element){
			var memberId=new Object();
			memberId.id=$(element).children("label").eq(0).children("span").data("id");
			memberArray[i]=memberId;
			i++;
		});
		if(memberArray.length=="0"){
			return null;
		}
		return memberArray;
	}
	//条件选人的信息基本信息
	function customerInfo(){		
		if($("#ruleShow").hasClass("icon-toggle-off")){
			return null;
		}
		var gender=$("#gender>span.icon-check-circle-o").data("value");
		var startAge=$("#startAge").val();
		var endAge=$("#endAge").val();
		var cityType=$("#cityType").val();
		var cityInfo=$("#cityInfo").attr("title");
		//city信息
		var cityId=$("#regions[data-index='1']").find("input[data-region-id]").val();
		var cityPid=$("#regions[data-index='1']").find("input[data-region-pid]").val();
		var startEdu=$("#startEdu").val();
		var endEdu=$("#endEdu").val();
		var startLevel=$("#startLevel").val();
		var endLevel=$("#endLevel").val();
		var customer=new Object();
		if(StringEmpty(gender)){
			customer.gender=gender;
		}
		if(StringEmpty(startAge)){
			customer.startAge=startAge;
		}
		if(StringEmpty(endAge)){
			customer.endAge=endAge;
		}
		if(StringEmpty(cityType)){
			customer.cityType=cityType;
		}
		if(StringEmpty(cityInfo)){
			customer.cityInfo=cityInfo;
			customer.cityId=cityId;
			customer.cityPid=cityPid;
		}
		if(StringEmpty(startEdu)){
			customer.startEdu=startEdu;
		}
		if(StringEmpty(endEdu)){
			customer.endEdu=endEdu;
		}
		if(StringEmpty(startLevel)){
			customer.startLevel=startLevel;
		}
		if(StringEmpty(endLevel)){
			customer.endLevel=endLevel;
		}		
		////console.log("---->customer:"+JSON.stringify(customer));
		if(JSON.stringify(customer) == "{}"){
			return null;
		}
		return customer;
	}
	///条件选人的rfm属性
	function rfmInfo(){
		if($("#ruleShow").hasClass("icon-toggle-off")){
			return null;
		}
		var rfmInfo=new Object();
		//关系
		var relation=$("#relation").val();
		var pre=getRfm("pre");
		var pos=getRfm("pos");
		if(StringEmpty(pre)){
			rfmInfo.pre=pre;
		}
		if(StringEmpty(pos)){
			rfmInfo.pos=pos;
		}
		if(StringEmpty(relation)){
			rfmInfo.relation=relation;
		}
		if(JSON.stringify(rfmInfo) == "{}"){
			return null;
		}
		////console.log("------>rfm"+JSON.stringify(rfmInfo));
		return rfmInfo;
	}
	//获得rfm中的条件
	function getRfm(name){
		//前置条件
		var pre=new Object();
		//前置行为
		var action=$("#"+name+"Action").val();
		if(StringEmpty(action)){
			pre.action=action;
		}
		//判断是否被选中
		if($("#"+name+" .icon-check-square")){
		//时间信息
			var dateType=$("#"+name+"DateType").val();
			var dateInfo=$("#"+name+"DateInfo").val();
			if(StringEmpty(dateType)){
				pre.dateType=dateType;
				if(StringEmpty(dateInfo)){
					pre.dateInfo=dateInfo;
				}
			}			
		}
		var preStatus=$("#"+name+"Status").val();
		//状态信息
		if(StringEmpty(preStatus)){
			pre.status=preStatus;
			var start=$("#"+name+"Start").val();
			var end=$("#"+name+"End").val();
			if(preStatus!="BUY_NUMBER"){
				start=start*100;
				end=end*100;
			}
			if(StringEmpty(start)){
				pre.start=start;
			}
			if(StringEmpty(end)){
				pre.end=end;
			}
		}
		if(JSON.stringify(pre) == "{}"){
			return null;
		}
		return pre;
	}
	//行为条件
	function customerActionInfo(){
		if($("#customerActionShow").hasClass("icon-toggle-off")||$("#customerActionShow").parent().parent().css("display") == "none"){
			return null;
		}
		var action=new Object();
		var type=$("#action .icon-check-circle-o").data("value");
		if(StringEmpty(type)){
			action.action=type;
		}
		if(JSON.stringify(action) == "{}"){
			return null;
		}
		////console.log("------>action"+JSON.stringify(action));
		return action;
	}
	//触发条件
	function tiggerInfo(){
		if($("#tiggerShow").hasClass("icon-toggle-off")){
			return null;
		}
		var tigger=new Object();
		var action=$("#customerAction").val();
		if(StringEmpty(action)){
			var info;
			if(action=="CREATE_CUSTOMER"){
				info=$("#customerLevel").val();
			}else if(action=="BUY"){
				var type=$("#buyInfo").val();
				if(type=="BUY_GOODS"){
					action=type;
					info=$("#goods").val();
				}else if(type="BUY_PRICE"){
					info=$("#priceInfo").val()*100;
					action=type;
				}else{
					action="BUY_PRICE";
				}
			}else if(action=="BALANCE"){
				info=$("#balanceInfo").val()*100;
			}else if(action=="BIRTHDAY"){
				info=$("#birthdayInfo").val();
			}
			tigger.type=action;
			if(StringEmpty(info)){
				tigger.info=info;
			}
		}
		if(JSON.stringify(tigger) == "{}"){
			return null;
		}
		////console.log("------>tigger"+JSON.stringify(tigger));
		return tigger;
	}
	//提交条件
	/* $("#ruleCommit").click(function(){
		ruleInfo();
	}) */	
	//条件信息
	function ruleInfo(){
		var flag=true;
		var rule=new Object();
		var tigger=tiggerInfo();
		if(StringEmpty(tigger)){
			rule.tigger=tigger;
		}
		var action=customerActionInfo();
		if(StringEmpty(action)){
			rule.action=action;
		}
		var rfm=rfmInfo();
		if(StringEmpty(rfm)){
			rule.rfm=rfm;
		}
		var customer=customerInfo();
		if(StringEmpty(customer)){
			rule.customer=customer;
		}
		var memberGroup=memberGroupInfo();
		if(StringEmpty(memberGroup)){
			rule.memberGroup=memberGroup;
		}
		//医药行业
		var medicineRule=medicineRuleInfo();
		if(StringEmpty(medicineRule)){
			rule.medicineRule=medicineRule;
		}else{
			normalSign=true;
		}
		commitIndex=$("#ruleCommit").attr("point");
		commitParentId=$("#ruleCommit").attr("index");
		if(!StringEmpty(commitParentId)){
			commitParentId=0;
		}
		if(JSON.stringify(rule) != "{}"){
			if(StringEmpty(rule.memberGroup)&&(StringEmpty(rule.customer)||StringEmpty(rule.rfm))){
				showErrorLong("分组不能和条件同时选择");
				flag=false;
			}else if(StringEmpty(rule.rfm)&&StringEmpty(rule.tigger)&&rule.tigger.action!="COUPON_CANCEL"){
				showErrorLong("会员状态和触发条件不能同时选择");
				flag=false;
			}else if(StringEmpty(rule.tigger)&&StringEmpty(rule.action)){
				showErrorLong("会员行为和行为条件不能同时选择");
				flag=false;
			}else if(StringEmpty(rule.medicineRule)&&(StringEmpty(rule.customer)||StringEmpty(rule.rfm)||StringEmpty(rule.tigger)||StringEmpty(rule.action)||StringEmpty(rule.memberGroup))){
				showErrorLong("根据门店交易选人只能单独选择");
				flag=false;
			}
			else{
				flag=checkPage(commitIndex);
				if(flag){
					$("#memberGroup .active-natty").removeClass("active-natty");
					commitData=rule;					
				}
			}
		}else{
			showError("请选择条件信息");
			flag=false;
		}		
		return flag;
	}
	//提交时间
	/* $("#dateCommit").click(function(){
		dateInfo();
	}) */
	//时间条件
	function dateInfo(){
		var flag=true;
		var date=new Object();
		commitIndex=$("#dateCommit").attr("point");
		commitParentId=$("#dateCommit").attr("index");
		var type=$("#dateInfo .icon-check-circle-o").data("value");
		//校验父节点是否是生日的触发条件
		var info;
		if(StringEmpty(commitIndex)){
			info=selectPointInfo(commitIndex);
			info=selectPointInfo(info.parentId);
		}else{
			info=selectPointInfo(commitParentId);
		}
		info=JSON.parse(info.pointInfo);
		if(StringEmpty(info)&&!StringEmpty(info.medicineRule)&&type=="USE_DATE"){
			showErrorLong("条件不是门店交易选人时，时间不能选择使用时间");
			flag=false;
		}else if(StringEmpty(info)&&StringEmpty(info.tigger)&&info.tigger.type=="BIRTHDAY"&&type!="NOW"){
			showErrorLong("触发条件为生日时，时间只能选择立即执行");
			flag=false;
		}else if(StringEmpty(type)){
			var dateInfo;
			if(type=="NOW"){
			} else if(type=="BIRTHDAY"){
				dateInfo=$("#birthdayInfo").val();
			}else if(type=="AFTER"){
				dateInfo=$("#afterInfo").val();
			}else if(type=="CUSTOM"){
				dateInfo=$("#customInfo").val();
			}else if(type=="USE_DATE"){
				var use_date=$("#use_date .icon-check-circle-o").data("value");
				var useInfo=new Object();
				if(use_date=="USE_AFTER"&&StringEmpty($("#use_after_info").val())){
					useInfo.type="AFTER";
					useInfo.info=$("#use_after_info").val();
					dateInfo=useInfo;
				}else if(use_date=="USE_BEFORE"&&StringEmpty($("#use_before_info").val())){
					useInfo.type="BEFORE";
					useInfo.info=$("#use_before_info").val();
					dateInfo=useInfo;
				}else{
					dateInfo=null;
				}
			}
			if(!StringEmpty(dateInfo)&&type!="NOW"){
				showError("请填写时间信息");
				flag=false;
				return flag;
			}
			if(type=="CUSTOM"&&StringEmpty(dateInfo)){
				var curDate = new Date();
				var curHour = curDate.getHours();	
				if(curHour<10){
					curHor="0"+curHour;
				}
				var curDay = curDate.getDate();
				if(curDay<10){
					curDay="0"+curDay;
				}
				var curMonth = curDate.getMonth()+1;
				if(curMonth<10){
					curMonth="0"+curMonth;
				}
				var curYear = curDate.getFullYear();
				var nowDate=curYear+"-"+curMonth+"-"+curDay;
				//2018-01-23 10
				var day=dateInfo.substring(0,10);
				var hour=dateInfo.substring(11,13);
				if(hour>=8&&hour<=22){
					//1.当天日期  大于当前小时，并且+3在8:00-22:00
					if(nowDate==day){
						if(hour>parseInt(curHour)+1){
							dateInfo=day+" "+hour+":00:00";
						}else{
							flag=false;
							showError("当天日期只能设置1个小时之后");
							return flag;
						}						
					}else{
						dateInfo+=":00:00";
					}
				}else{
					flag=false;
					showErrorLong("自定义时间只能设置8:00-22:00点之间");
					return flag;
				}
			}
			date.type=type;
			if(StringEmpty(dateInfo)){
				date.info=dateInfo;
			}
			//判断是修改还是新增
			commitData=date;
		}else{
			showError("请选择时间信息");
			flag=false;
		}
		return flag;
	}
	//动作信息
	function actionInfo(){
		var flag=true;
		var action=new Object();
		var type=$("#actionType").val();
		commitIndex=$("#actionCommit").attr("point");
		commitParentId=$("#actionCommit").attr("index");
		if(StringEmpty(type)){
			action.type=type;		
			var id=$("#actionId").html();
			if(StringEmpty(id)){
				action.id=id;
				commitData=action;
				$("#actionId").html(null);
			}else{
			 showError("请选择动作模板信息");
			 flag=false;
			}
		}else{
			showError("请选择动作信息");
			flag=false;
		}
		return flag;
	}
	//校验提表数据
	function validateInfo(type){
		var flag=true;
		if(type=="1"){
			flag=ruleInfo();
		}else if(type=="2"){
			flag=dateInfo();
		}else if(type=="3"){
			flag=actionInfo();
		}
		return flag;
	}
	//提交节点信息
	function savePointInfo(data,type,parentId){
		var flag=true;
		var addPointInfoUrl=path+"/autoMarketTempPoint/addTempPointInfo";
			$.ajax({
	 			type:"post",
	  			url:addPointInfoUrl,
	  			async: false,
	  			data:{"cid" : cid,
	            	"pointInfo":JSON.stringify(data),
	            	"pointType":type,
	            	"pointId":pointId,
	            	"templateId":templateId,
	            	"parentPointId":parentId,
	            	"taskId":taskId
	            	},success:function(data){
					if(data.status==200){
						if(type=="3"){
							taskId++;
						}
						pointId++;
						flag=true;
					}else{
						showError(data.message);
						flag=false;
					}}
			});
			return flag;
	}
	//修改节点信息
	function updatePointInfo(id,data){
		var updateFlag=true;
		var updatePointInfoUrl=path+"/autoMarketTempPoint/updateTempPointInfoByPointIdAndTemplateId";
		$.ajax({
 			type:"post",
  			url:updatePointInfoUrl,
  			async: false,
  			data:{"cid" : cid,
            	"pointInfo":JSON.stringify(data),
            	"pointId":id,
            	"templateId":templateId
            	},success:function(data){
            		updateFlag=true;
				/* if(data.status==200){
					updateFlag=true;
				}else{
					showError(data.message);
					updateFlag=false;
				} */}
		});	
		return updateFlag;
	}
	//根据父节点Id校验是否可以添加
	function validateTypeByParent(index,type){
		var flag=true;
		var validateUrl=path+"/autoMarketTempPoint/validateTempPointTypeByDto";
		$.ajax({
 			type:"post",
  			url:validateUrl,
  			async: false,
  			data:{"cid" : cid,
            	"parentPointId":index,
            	"pointType":type,
            	"templateId":templateId
            	},success:function(data){
				if(data.status==200){
					flag=true;
				}else{
					showError(data.message);
					flag=false;
				}}
		});	
		return flag;
	}
	$("#save").click(function(){
		var flag=true;
		flag=validateTypeByParent(commitIndex,1);
		if(flag){
			flag=validateTemplateInfo();
		}		
		if(flag){
			saveTemplate();
		}
	})
	//保存模板信息
	function saveTemplate(){
		var flag=true;
		var saveUrl=path+"/automarket/updateAutoMarketTemplate";
		var name=$("#moduleNameText").val();
		$.ajax({
 			type:"post",
 			url:saveUrl,
  			async: false,
  			data:{"cid" : cid,
            	"name":name,
            	"id":templateId
            	},success:function(data){
				if(data.status==200){
					window.location.href=path+"/view/automarket/customList";
				}else{
					showError(data.message);
					flag=false;
				}}
		});	
		return flag;
	}
	//预览内容
	function setHtml(info,type){
		var content = "<div style='padding: 1em;'>";
		if(type=="1"){
			var result=JSON.parse(info.pointInfo);
			if(StringEmpty(result.memberGroup)){
				var array=result.memberGroup;
				content+="<div class='block-inner-line'><div><label><b>分组选人</b></label></div><div>";
				for(var i=0;i<array.length;i++){			
					var count=0;
					if(StringEmpty(array[i].count)){
						count=array[i].count;
					}
					content+="<label>"+array[i].name+"（"+count+"）人</label>";
				}
				content+="</div></div>";
			}
			if(StringEmpty(result.customer)||StringEmpty(result.rfm)){
				var customer=result.customer;
				content+="<div class='block-inner-line'><div><label><b>条件选人</b></label></div><div>";
				if(StringEmpty(customer)){
					if(StringEmpty(customer.gender)){
						var gender=customer.gender;
						var text= gender == "m" ? "男" : gender == "f" ? "女" : "未知";
					content+="<label><span>性别</span><span>"+text+"</span></label>";
					}
					if(StringEmpty(customer.startAge)||StringEmpty(customer.endAge)){					
					content+="<label><span>年龄</span><span>"+customer.startAge+"至"+customer.endAge+"岁</span></label>";
					}

					if(StringEmpty(customer.cityInfo)){
						var city=customer.cityInfo;
						var type=customer.cityType;
						var text= type == "remove" ? "排除" : type== "include" ? "包括" : "所有";
						if(text=="所有"){
							content+="<label><span>地区</span><span>全部</span></label>";
						}else{
							content+="<label><span>地区</span><span>"+text+""+city+"</span></label>";
						}
					}
					if(StringEmpty(customer.startEdu)||StringEmpty(customer.endEdu)){
						if(!StringEmpty(customer.startEdu)&&StringEmpty(customer.endEdu)){
							content+="<label><span>教育水平</span><span>"+customer.startEdu+"以上</span></label>";
						}
						if(StringEmpty(customer.startEdu)&&!StringEmpty(customer.endEdu)){
							content+="<label><span>教育水平</span><span>"+customer.startEdu+"以下</span></label>";
						}
						if(StringEmpty(customer.startEdu)&&StringEmpty(customer.endEdu)){
							content+="<label><span>教育水平</span><span>"+customer.startEdu+"至"+customer.endEdu+"</span></label>";
						}
					}
					if(StringEmpty(customer.startLevel)||StringEmpty(customer.endLevel)){
						if(!StringEmpty(customer.startLevel)&&StringEmpty(customer.endLevel)){
							content+="<label><span>会员等级</span><span>"+customer.startLevel+"级以上</span></label>";
						}
						if(StringEmpty(customer.startLevel)&&!StringEmpty(customer.endLevel)){
							content+="<label><span>会员等级</span><span>"+customer.endLevel+"级以下</span></label>";
						}
						if(StringEmpty(customer.startLevel)&&StringEmpty(customer.endLevel)){
						content+="<label><span>会员等级</span><span>"+customer.startLevel+"至"+customer.endLevel+"级</span></label>";
						}
					}
				}				
				var rfm=result.rfm;
				if(StringEmpty(rfm)&&StringEmpty(rfm.pre)){
					var pre=rfm.pre;
					 var action=pre.action;
					 var status=pre.status;
					 if(StringEmpty(pre)){
						 content+= "<label><span>会员状态</span>";
						 if(StringEmpty(pre.dateInfo)&&StringEmpty(pre.dateType)){
								var dateType=pre.dateType=="BEFORE"?"之前":"以内";
								content+="<span>"+pre.dateInfo+"天"+dateType+"</span>";
							}
							var preAction= action == "CREATE_CUSTOMER" ? "新建会员" : action == "BUY_GOODS" ? "购买商品" :action=="BUY_PRICE"? "购物消费":action=="NO_PRICE"?"未消费":"会员储值";
							content+= "<span>"+preAction+"</span>";
							if(StringEmpty(status)){
								var preStatus= status == "BUY_NUMBER" ? "购买次数" :status == "BUY_PRICE" ? "购买金额" :status == "MAX_PRICE" ? "最高消费":status == "AVG_PRICE"?"平均消费":"会员储值";
								content+="<span>"+preStatus+"</span>";
							}
							if(StringEmpty(pre.start)){
								if(status=="BUY_NUMBER"){
									content+="<span>"+pre.start+"</span>";
								}else{
									content+="<span>"+(pre.start)/100+"</span>";
								}
							}
							if(StringEmpty(pre.start)&&StringEmpty(pre.end)){
								if(status=="BUY_NUMBER"){
									content+="<span>至"+pre.end+"</span>";
								}else{
									content+="<span>至"+(pre.end)/100+"</span>";
								}
							}else if(StringEmpty(pre.end)){
								if(status=="BUY_NUMBER"){
									content+="<span>"+pre.end+"以下</span>";
								}else{
									content+="<span>"+(pre.end)/100+"以下</span>";
								}
							}
							content+="</label>";
					 }
					if(StringEmpty(rfm.relation)){
						var relation= rfm.relation=="and" ? "并且" :rfm.relation=="or"?"或者":"不是";
						content+="<label><b style='margin-left: 5.2em;'></b><span>"+relation+"</span>";
					}
					if(StringEmpty(rfm.pos)){
						var pos=rfm.pos;
						 action=pos.action;
						 status=pos.status;
						 if(StringEmpty(action)){
							 	if(StringEmpty(pos.dateInfo)&&StringEmpty(pos.dateType)){
									var dateType=pos.dateType=="BEFORE"?"之前":"以内";
									content+="<span>"+pos.dateInfo+"天"+dateType+"</span>";
								}
								var posAction= action == "CREATE_CUSTOMER" ? "新建会员" : action == "BUY_GOODS" ? "购买商品" :action=="BUY_PRICE"? "购物消费":action=="NO_PRICE"?"未消费":"会员储值";
								content+= "<span>"+posAction+"</span>";
								if(StringEmpty(status)){
									var posStatus= status == "BUY_NUMBER" ? "购买次数" :status == "BUY_PRICE" ? "购买金额" :status == "MAX_PRICE" ? "最高消费":status == "AVG_PRICE"?"平均消费":"会员储值";
									content+="<span>"+posStatus+"</span>";
								}
								if(StringEmpty(pos.start)){
									if(status=="BUY_NUMBER"){
										content+="<span>"+pos.start+"</span>";
									}else{
										content+="<span>"+(pos.start)/100+"</span>";
									}
								}
								if(StringEmpty(pos.start)&&StringEmpty(pos.end)){
									if(status=="BUY_NUMBER"){
										content+="<span>至"+pos.end+"</span>";
									}else{
										content+="<span>至"+(pos.end)/100+"</span>";
									}
								}else if(StringEmpty(pos.end)){
									if(status=="BUY_NUMBER"){
										content+="<span>"+pos.end+"以下</span>";
									}else{
										content+="<span>"+(pos.end)/100+"以下</span>";
									}
								}
								content+="</label></div>";
						 }					
					}	
			}
				content+="</div></div>";
		}
			if(StringEmpty(result.action)){
				var action=result.action;
				var text = action.action == "NO_CANCEL" ? "未核销" : action.action== "CANCEL" ? "核销" : "提表";
				//var text = action == "NO_CANCEL" ? "未核销" : (action== "CANCEL" ? "核销" : "提表");
				content+="<div class='block-inner-line'><div><label><b>行为选人</b></label></div><div><label><span>用户行为</span><span>"+text+"</span></label></div></div>";;
			}
			if(StringEmpty(result.tigger)){
				var tigger=result.tigger;
				var text= tigger.type == "CREATE_CUSTOMER" ? "新建会员" : tigger.type== "BUY_GOODS" ? "购买商品" :tigger.type=="BUY_PRICE"? "购买金额":tigger.type=="BIRTHDAY"?"会员生日":tigger.type=="COUPON_CANCEL"?"卡券核销":"会员储值";
				content+="<div class='block-inner-line'><div><label><b>触发条件选人</b></label></div><div><label><span>用户行为</span><span>"+text+"</span>";
				if(StringEmpty(result.tigger.info)){
					if(tigger.type=="BUY_PRICE"||tigger.type=="BALANCE"){
						content+="<span>"+(tigger.info)/100+"</span>";
					}else{
						content+="<span>"+tigger.info+"</span>";
					}
				}
				content+="</label></div></div>";
			}
			//医药行业
			if(StringEmpty(result.medicineRule)){
				content+=showMedicineInfo(result,"1");
			}
		}else if(type==2){
			var result=JSON.parse(info.pointInfo);
			var type=result.type;
			var text= type == "NOW" ? "现在" :type== "BIRTHDAY" ? "生日" :type=="CUSTOM"?"自定义时间":type=="AFTER"?"倒计时":"使用时间";
			if(type=="NOW"){
				content += "<div class='block-inner-line'><div><label><b>设置时间</b></label></div><div><label>"+text+"";
			}else{
				content += "<div class='block-inner-line'><div><label><b>设置时间</b></label></div><div><label><span>"+text+"</span>";
			}
			if(StringEmpty(type=="CUSTOM")){
				content+="<span>"+result.info+"点</span>";
			}
			if(StringEmpty(type=="AFTER")){
				content+="<span>倒计时"+result.info+"天之后</span>";
			}
			if(StringEmpty(type=="USE_DATE")){
				content+=showMedicineInfo(result,"2");
			}
			content+="</label></div></div>";
		}else if(type=="3"){
			info=JSON.parse(info.pointInfo);
			var arrive_count=0;
			var click_count=0;
			var submit_count=0;		
			var send_count=0;
			var write_off_num=0;
			var write_off_count=0;
			var name=templateName;
			if(StringEmpty(info)&&(StringEmpty(info.send_count))){
				arrive_count=info.arrive_count;
				click_count=info.click_count;
				submit_count=info.submit_count;			
				send_count=info.send_count;
			}
			//var text=type=="SMS"?"短信":"优惠券";
			content += "<div class='block-inner-line'><div><label>名称</label></div><div><label>"+name+"</label></div></div>"
			+ "<div class='block-inner-line'><div><label>发送量</label></div><div><label>"+send_count+"</label></div></div>";
			content+= "<div class='block-inner-line'><div><label>到达量</label></div><div><label>"+arrive_count+"</label></div></div>";
			if(StringEmpty(info)&&info.type!=3){
				content+="<div class='block-inner-line'><div><label>点击量</label></div><div><label>"+click_count+"</label></div></div>"
				+ "<div class='block-inner-line'><div><label>提交表单</label></div><div><label>"+submit_count+"</label></div></div>";
			}			
			if(StringEmpty(info)&&StringEmpty(info.write_off_count)){
				write_off_num=info.write_off_num;
				write_off_count=info.write_off_count;					
			}				
			if(StringEmpty(info.type)&&info.type==2){
				content+="<div class='block-inner-line'><div><label>核销量</label></div><div><label>"+write_off_num+"</label></div></div>";
				content+="<div class='block-inner-line'><div><label>核销总额</label></div><div><label>"+write_off_count+"</label></div></div>";
			}				
		}
		content+="</div>";
		$("#info-block").find(".iziModal-content").html(content);
	}
	//判断字符串是否为空
    function StringEmpty(content) {
        if (content == undefined || content == "" || content == null) {
            return false;
        } else {
            return true;
        }
    }
  //查询节点信息
	function selectPointInfo(index){
		var info="";
		var findInfoUrl=path+"/autoMarketTempPoint/findTempPointInfoByDto";
		$.ajax({
 			type:"post",
 			url:findInfoUrl,
  			async: false,
  			data:{"cid" : cid,
            	"pointId":index,
            	"templateId":templateId
            	},success:function(data){
				if(data.status==200){
					info=data.data;
					//setHtml(info,type);
				}else{
					showError(data.message);
				}}
		});		
		return info;
	}
	//查询节点信息
	function searchActionInfo(index){
		var findInfoUrl=path+"/autoMarketTempPoint/findTempPointInfoByDto";
		$.ajax({
 			type:"post",
 			url:findInfoUrl,
  			async: false,
  			data:{"cid" : cid,
            	"pointId":index,
            	"templateId":templateId
            	},success:function(data){
				if(data.status==200){
					var result=data.data;				
					result=JSON.parse(result.pointInfo);
					actionTypeInfo=result.type;
					actionParams="&type=edit&id="+result.id;
					
				}else{
					showError(data.message);
				}}
		});		
	}
	//查询模板信息
	function findTemplateInfo(id){
		var findInfoUrl=path+"/automarket/findAutoMarketTemplateById";
		$.ajax({
 			type:"post",
 			url:findInfoUrl,
  			async: false,
  			data:{"cid" : cid,
            	"id":id
            	},success:function(data){
				if(data.status==200){
					templateName=data.data.name;
				}else{
					showError(data.message);
				}}
		});		
	}
	//校验名称是否重复
	function checkAutomationTemplateByName(name){
		var flag=true;
		var checkNameUrl=path+"/automarket/findTemplateCountByName";
		$.ajax({
 			type:"post",
 			url:copyUrl,
  			async: false,
  			data:{"cid" : cid,
            	"name":name
            	},success:function(data){
				if(data.status!=200){
					flag=true;
				}else{
					showError("模板名称已存在");
					flag=false;
				}
			}
		});
		return flag;
	}
	//预览节点信息
	function loadInfoByPoint(index,id,type){
		var info=selectPointInfo(index);
		setHtml(info,type);
	}
	function showError(info) {
		var modal = $("#alert-block").iziModal();
		modal.iziModal('setHeaderColor', 'rgb(202,38,0)');
		modal.iziModal('setTitle', info);
		modal.iziModal('open');
	}
	function findMax(data){
		var info;
		var findMaxUrl=path+"/autoMarketTempPoint/findTempMaxPointInfoByTemplateId";
		$.ajax({
 			type:"post",
 			url:findMaxUrl,
  			async: false,
  			data:{"cid" : cid,
            	"templateId":data
            	},success:function(data){
				if(data.status==200){
					info=data.data;
					taskId=parseInt(info.taskId)+1;
					pointId=parseInt(info.pointId)+1;
				}else{
					showError(data.message);
				}}
		});	
	}
	//数据回显
	function dataEcho(type,id){
		//预览节点信息
		var info=selectPointInfo(id);		
		info=JSON.parse(info.pointInfo);
		if(StringEmpty(info)&&type==1){
			$("#relation").prop("disabled",false);
			if(StringEmpty(info.memberGroup)){
				var memberGroup=info.memberGroup;
				for(var i=0;i<memberGroup.length;i++){
					$("#memberGroup").find("span[data-id='"+memberGroup[i].id+"']").parent().parent().addClass("active-natty");
				}
			}
			if(StringEmpty(info.medicineRule)){
				setMedicineInfo(info,"1");
			}
			if(StringEmpty(info.customer)){
				var customer = info.customer;
				if(StringEmpty(customer.gender)){
					var gender=customer.gender;
					if(gender=="m"){
						$("#gender").find("span[data-value='m']").removeClass("icon-circle-o").addClass("icon-check-circle-o").addClass("coat-green");
					}else if(gender=="f"){
						$("#gender").find("span[data-value='f']").removeClass("icon-circle-o").addClass("icon-check-circle-o").addClass("coat-green");
					}else{
						$("#gender").find("span[data-value='u']").removeClass("icon-circle-o").addClass("icon-check-circle-o").addClass("coat-green");
					}
				}
				if(StringEmpty(customer.startAge)){
					$("#startAge").val(customer.startAge);
				}
				if(StringEmpty(customer.endAge)){
					$("#endAge").val(customer.endAge);
				}
				if(StringEmpty(customer.cityType)){
					var numbers=$("#cityType").find("option");
					var cityType=customer.cityType;
					if(cityType=="include"){
						$(numbers[1]).prop("selected","selected");
					}else if(cityType=="remove"){
						$(numbers[2]).prop("selected","selected");
					}else if(cityType=="all"){
						$(numbers[0]).prop("selected","selected");
					}
					$("#cityType").trigger("change");
					if(StringEmpty(customer.cityInfo)){
						$("#cityInfo").attr("title",customer.cityInfo);
						$("#regions[data-index='1']").find("input[data-region-id]").val(customer.cityId);
						$("#regions[data-index='1']").find("input[data-region-pid]").val(customer.cityPid);
						var _text=customer.cityInfo;
						var showText;
						if(_text.length > 7) {
							showText = _text.substr(0, 6) + "...";
						} else {
							showText = _text;
						}
						$("#cityInfo").html(showText);
					}
				}
			}
			if(StringEmpty(info.rfm)){
				var rfm=info.rfm;
				if(StringEmpty(rfm.pre)){
					$("#pre").parent().find("select").prop("disabled",false);
					$("#pre").parent().find("input").prop("disabled",false);
					//$("#preStatus").prop("disabled",false);
					var pre=rfm.pre;
					if(StringEmpty(pre.action)){
						var action=pre.action;
						var numbers=$("#preAction").find("option");
						if(action=="BUY_PRICE"){
							$(numbers[2]).prop("selected","selected");
						}else if(action=="CREATE_CUSTOMER"){
							$(numbers[1]).prop("selected","selected");							
						}else if(action=="NO_PRICE"){
							$(numbers[3]).prop("selected","selected");							
						}
						$("#preAction").trigger("change");
					}
					if(StringEmpty(pre.dateType)){
						$("#pre").find(".boxer").removeClass("icon-square-o").addClass("coat-green").addClass("icon-check-square").next().removeClass("disable-starry").find("input").prop("disabled", false);						
						var dateType=pre.dateType
						var numbers=$("#preDateType").find("option");
						if(dateType=="INNER"){
							$(numbers[2]).prop("selected","selected");
						}else if(dateType=="BEFORE"){
							$(numbers[1]).prop("selected","selected");		
						}
						$("#preDateType").trigger("change");
					}
					if(StringEmpty(pre.dateInfo)){
						var dateInfo=pre.dateInfo;
						$("#preDateInfo").val(dateInfo);
					}else{
						$("#preDateInfo").prop("disabled",true);
					}
					//$("#posDateInfo").prop("disabled",true);
					if(StringEmpty(pre.status)){
						var status=pre.status;
						var numbers=$("#preStatus").find("option");
						if(status=="BUY_NUMBER"){
							$(numbers[1]).prop("selected","selected");	
						}else if(status=="BUY_PRICE"){
							$(numbers[2]).prop("selected","selected");	
						}else if(status=="AVG_PRICE"){
							$(numbers[3]).prop("selected","selected");	
						}else if(status=="MAX_PRICE"){
							$(numbers[4]).prop("selected","selected");	
						}
						$("#preStatus").trigger("change");
						if(status=="BUY_NUMBER"){
							if(StringEmpty(pre.start)){
								$("#preStart").val(pre.start);
							}
							if(StringEmpty(pre.end)){
								$("#preEnd").val(pre.end);
							}
						}else{
							if(StringEmpty(pre.start)){
								$("#preStart").val((pre.start)/100);
							}
							if(StringEmpty(pre.end)){
								$("#preEnd").val((pre.end)/100);
							}
						}
					}					
				}
				if(StringEmpty(rfm.relation)){
					var relation=rfm.relation;
					var numbers=$("#relation").find("option");
					if(relation=="and"){
						$(numbers[1]).prop("selected","selected");	
					}else if(relation=="or"){
						$(numbers[2]).prop("selected","selected");	
					}else if(relation=="not"){
						$(numbers[3]).prop("selected","selected");	
					}
					$("#relation").trigger("change");
				}
				if(StringEmpty(rfm.pos)){
					$("#pos").parent().find("select").prop("disabled",false);
					$("#pos").parent().find("input").prop("disabled",false);
					//$("#posStatus").prop("disabled",false);
					var pos=rfm.pos;
					if(StringEmpty(pos.action)){
						var action=pos.action;
						var numbers=$("#posAction").find("option");
						if(action=="BUY_PRICE"){
							$(numbers[2]).prop("selected","selected");
							$(".took-panel").find("select[data-tag='rfm'][data-team='"+2+"']").find("option[data-label!='5']").prop("disabled", false);
							$(".took-panel").find("select[data-tag='rfm'][data-team='"+2+"']").find("option[value='']").prop("disabled", false);
						}else if(action=="CREATE_CUSTOMER"){
							$(numbers[1]).prop("selected","selected");							
						}else if(action=="NO_PRICE"){
							$(numbers[3]).prop("selected","selected");							
						}
						$("#posAction").trigger("change");
					}
					if(StringEmpty(pos.dateType)){
						$("#pos").find(".boxer").removeClass("icon-square-o").addClass("coat-green").addClass("icon-check-square").next().removeClass("disable-starry").find("input").prop("disabled", false);						
						var dateType=pos.dateType
						var numbers=$("#posDateType").find("option");
						if(dateType=="INNER"){
							$(numbers[2]).prop("selected","selected");
						}else if(dateType=="BEFORE"){
							$(numbers[1]).prop("selected","selected");		
						}
						$("#posDateType").trigger("change");
					}
					if(StringEmpty(pos.dateInfo)){
						var dateInfo=pos.dateInfo;
						$("#posDateInfo").val(dateInfo);
						$("#posDateInfo").prop("disabled",false);
					}else{
						$("#posDateInfo").prop("disabled",true);
					}
					if(StringEmpty(pos.status)){
						var status=pos.status;
						var numbers=$("#posStatus").find("option");
						if(status=="BUY_NUMBER"){
							$(numbers[1]).prop("selected","selected");	
						}else if(status=="BUY_PRICE"){
							$(numbers[2]).prop("selected","selected");	
						}else if(status=="AVG_PRICE"){
							$(numbers[3]).prop("selected","selected");	
						}else if(status=="MAX_PRICE"){
							$(numbers[4]).prop("selected","selected");	
						}
						$("#posStatus").trigger("change");
						if(status=="BUY_NUMBER"){
							if(StringEmpty(pos.start)){
								$("#posStart").val(pos.start);
							}
							if(StringEmpty(pos.end)){
								$("#posEnd").val(pos.end);
							}
						}else{
							if(StringEmpty(pos.start)){
								$("#posStart").val((pos.start)/100);
							}
							if(StringEmpty(pos.end)){
								$("#posEnd").val((pos.end)/100);
							}
						}
					}					
				}
			}
			if(StringEmpty(info.action)){
				var action=info.action;
				if(action.action=="NO_CANCEL"){
					$("#action").find("span[data-value='NO_CANCEL']").removeClass("icon-circle-o").addClass("icon-check-circle-o").addClass("coat-green");
				}else if(action.action=="CHANGE"){
					$("#action").find("span[data-value='CHANGE']").removeClass("icon-circle-o").addClass("icon-check-circle-o").addClass("coat-green");
				}else if(action.action=="CANCEL"){
					$("#action").find("span[data-value='CANCEL']").removeClass("icon-circle-o").addClass("icon-check-circle-o").addClass("coat-green");						
				}
			}
			if(StringEmpty(info.tigger)){
				var tigger=info.tigger;
				var numbers = $("#customerAction").find("option"); 
				if(tigger.type=="CREATE_CUSTOMER"){
					$(numbers[1]).prop("selected","selected");
				}else if(tigger.type=="BUY_PRICE"||tigger.type=="BUY_GOODS"){
					$(numbers[2]).prop("selected","selected");
					numbers=$("#buyInfo").find("option");
					if(tigger.type=="BUY_PRICE"){
						$(numbers[2]).prop("selected","selected");
						$("#priceInfo").val(tigger.info).parent().attr("style","display:block");
					}else if(tigger.type=="BUY_GOODS"){
						$(numbers[1]).prop("selected","selected");
						$("#goodsName").val(tigger.info).parent().attr("style","display:block");
					}
				}else if(tigger.type=="BIRTHDAY"){
					$(numbers[3]).prop("selected","selected");
					$("#birthdayInfo").parent().attr("style","display:block");
					$("#birthdayInfo").val(tigger.info);
				}else if(tigger.type=="COUPON_CANCEL"){
					$(numbers[4]).prop("selected","selected");
				}
				$(".took-panel").find("#customerAction").change();
			}
		}else if(type==2){
			if(info.type=="NOW"){
				$("#dateInfo").find("span[data-value='NOW']").removeClass("icon-circle-o").addClass("icon-check-circle-o").addClass("coat-green");
			}else if(info.type=="CUSTOM"){
				$("#dateInfo").find("span[data-value='CUSTOM']").removeClass("icon-circle-o").addClass("icon-check-circle-o").addClass("coat-green");
				var date=null;
				if(StringEmpty(info.info)){
					date=info.info.substring(0,13);
				}
				$("#customInfo").val(date);
				$("#customInfo").prop("disabled",false);
			}else if(info.type=="AFTER"){
				$("#dateInfo").find("span[data-value='AFTER']").removeClass("icon-circle-o").addClass("icon-check-circle-o").addClass("coat-green");
				$("#afterInfo").val(info.info);
				$("#afterInfo").prop("disabled",false);
			}else if(info.type=="USE_DATE"){
				setMedicineInfo(info.info,"2");
			}
		}
	}
	/*********************************医药行业相关********************************/
 	//选择医药条件标识
 	var medicineFlag=false;
 	//选择正常条件标识
 	var normalSign=false;
 	$(function(){
 		//医药行业标识
 	 	var industry=null;
 	 	industry=getCompanyInfo();
 		initIndustryInfo(industry);
 		initGoodsInfo();
 		initRuleInfo();
 	});
 	//查询企业信息
 	function getCompanyInfo(){
 		var industry;
 		var companyInfoUrl=path+"/company/ajaxCompanyInfo";
 		$.ajax({
 			type:"post",
 			url:companyInfoUrl,
  			async: false,
  			data:{"id" : cid
            	},success:function(data){
				if(data.status==200){
					industry=data.data.industryType;;
				}}
		});	
 		return industry;
 	}
 	//初始化条件信息
 	function initRuleInfo(){
 		var info;
 		var url=path+"/autoMarketTempPoint/findTempPointListByDto";
		$.ajax({
 			type:"post",
 			url:url,
  			async: false,
  			data:{"cid" : cid,
            	"templateId":templateId
            	},success:function(data){
				if(data.status==200){
					info=data.data;
				}
            }
		});
		if(StringEmpty(info)){
			info=selectPointInfo(info[0].id);
		}
		if(StringEmpty(info)&&StringEmpty(info.medicineRule)){
			medicineFlag=true;
		}else{
			normalSign=true;
		}
 	}
 	//隐藏非医药行业条件
 	function hideDontMedicineRule(){
 		$(".took-layers").find("div.layer-block[data-action='1']").hide();
 		$(".took-layers").find("div.layer-block[data-action='2']").hide();
 		$(".took-layers").find("div.layer-block[data-action='3']").hide();
 		$(".took-layers").find("div.layer-block[data-action='4']").hide();
 	}
 	//初始化行业属性
 	function initIndustryInfo(industry){
 		if(StringEmpty(industry)&&industry=="1"){
 			//条件
 			$("#store_trade_info").attr("style","display:block;");
 			//时间
			$("#use_date").parent().attr("style","display:block;");
 			//动作
 			var options=$("#actionType").find("option");
 			$(options[3]).attr("style","display:block;");
 	  	}else{
 	  		//条件
  			$("#store_trade_info").attr("style","display:none;");
			$("#store_trade_info").removeClass("icon-toggle-on").removeClass("coat-green").addClass("icon-toggle-off").addClass("coat-gray");
			//时间
			$("#use_date").parent().attr("style","display:none;");
			//动作
			var options=$("#actionType").find("option");
 			$(options[3]).attr("style","display:none;");
 		}
 	}	
	var goodsArray={};
	//医药行业
	$("#store_trade_info").off("click", ".check-natty");
	$("#store_trade_info").on("click", ".check-natty", function(){
		var $cur = $(this).parent().parent();
		$("#store_trade_info .sure").attr("value","确认");
		if(!$cur.hasClass("active-natty")) {
			$("#store_trade_goods").attr("style","display:block;");
		}else{
			$("#store_trade_goods").attr("style","display:none;");
		}
	});
	//获取条件
	function medicineRuleInfo(){
		if($("#store_trade_info .group-check").hasClass("icon-toggle-off")){
			return null;
		}
		if(!$("#store_trade_info .coat-natty").hasClass("active-natty")){
			return null;
		}
		var medicineRule=new Object();
		var medicineIds=new Array();		
		$(".choicebg").find("span").each(function(i){
			medicineIds[i]=$(this).data("id");
		});
		if(medicineIds.length==0){
			return null;
		}
		medicineRule.type="BUY_GOODS";
		medicineRule.info=medicineIds;
		//选中医药行业标识
		medicineFlag=true;
		return medicineRule;
	}
		//验证动作是否能选择
		function validateAction(index,type){
			var flag=true;
			var update=$("#actionCommit").attr("update");
			//插入的时候进行校验
			if(update=="1"){
				var info=selectPointInfo(index);
				/* if(type!="MEDICINE"&&info.type=="USE_DATE"){
					showErrorLong("时间条件为使用时间，动作只能是使用医药行业");
					flag=false;
				} */
				info=selectPointInfo(info.parentId);
				info=JSON.parse(info.pointInfo);
				if(type=="MEDICINE"&&!StringEmpty(info.medicineRule)){
					showErrorLong("条件不是按门店交易选人，动作不能是医药行业");
					flag=false;
				}
			}
			return flag;
		}
		//医药行业预览
		function showMedicineInfo(result,type){
			var content="";
			if(type=="1"){
				var medicineRule=result.medicineRule;
				content+='<div class="block-inner-line"><div><label><b>门店交易选人</b></label></div><div><label>购买商品</label>';
				for(var i=0;i<medicineRule.length;i++){
					content+="<label>"+medicineRule[i].goodsName+"</label>";
				}
				content+="</div></div>";
			}else if(type=="2"){
				result=result.info;
				if(result.type=="AFTER"){
					content+="<span>使用完后"+result.info+"天</span>";
				}else if(result.type=="BEFORE"){
					content+="<span>使用完前"+result.info+"天</span>";
				}
			}		
			return content;
		}
		//医药行业数据回显
		function setMedicineInfo(info,type){
			if(type=="1"){
				$("#select_goods").empty();
				$("#store_trade_info .sure").attr("value","确认");
				if(!$("#store_trade_info").find(".coat-natty").hasClass("active-natty")){
					$("#store_trade_info").find(".coat-natty").addClass("active-natty");
				}		
				$("#store_trade_goods").attr("style","display:block;");
				var medicineRule=info.medicineRule;
				var html="<div class='choicebg2'>";
				for(var i=0;i<medicineRule.length;i++){
					html+="<span class='item' data-id='"+medicineRule[i].goodsNumber+"'>";
					html+="<div class='closebg'>";
					html+="<a class='close'>";
					html+="<img src='<%=path%>/images/automation/close.png' height='16' width='16'>";
					html+="</a>";
					html+="</div>"+replaceUndefined(medicineRule[i].goodsName);
					html+="<table cellspacing='0' class='tablelist3'>";
	                html+="<thead><tr><th width='87px'>商品名</th>";
	                html+="<th>通用名</th>";
	                html+="<th>规格</th>";
	                html+="<th width='80px'>生产厂商</th>";
	                html+="<th width='80px'>批准文号</th>";
	                html+="<th>编码</th>";
	                html+="</tr></thead>";              
	                html+="<tbody><tr>";
		            html+="<td>"+replaceUndefined(medicineRule[i].goodsName)+"</td>";
		 	        html+="<td>"+replaceUndefined(medicineRule[i].generalName)+"</td>";
		 	        html+="<td>"+replaceUndefined(medicineRule[i].usageDosage)+"</td>";
		 	      	html+="<td>"+replaceUndefined(medicineRule[i].productionCompany)+"</td>";
		 	  		html+="<td>"+replaceUndefined(medicineRule[i].approvalNumber)+"</td>";
		 			html+="<td style='border-right:none!important;'>"+medicineRule[i].goodsNumber+"</td>";
		 			html+="<td style='display:none;'>"+medicineRule[i].goodsNumber+"</td>";
		            html += "</tr> </tbody> </table>";
					html+="</span>";	
				}			
				$(".choicebg").attr("style","display:block;");
				$(".choicebg").html(html);
				 $(".close").click(function() {
		          	$(this).parent().parent().remove();
		         });
				 $(".choicebg2>span").hover(function(){
	                 $(this).find("table").show();       
	                },function(){
	                  $(this).find("table").hide();      
	                });
			}else if(type=="2"){
				$("#dateInfo").find("span[data-value='USE_DATE']").removeClass("icon-circle-o").addClass("icon-check-circle-o").addClass("coat-green");
				if(info.type=="AFTER"){
					$("#dateInfo").find("span[data-value='USE_AFTER']").removeClass("icon-circle-o").addClass("icon-check-circle-o").addClass("coat-green");
					$("#use_after_info").val(info.info);
					$("#use_after_info").prop("disabled",false);
				}else if(info.type=="BEFORE"){
					$("#dateInfo").find("span[data-value='USE_BEFORE']").removeClass("icon-circle-o").addClass("icon-check-circle-o").addClass("coat-green");
					$("#use_before_info").val(info.info);
					$("#use_before_info").prop("disabled",false);
				}
			}
		}
	//验证是否可以保存模板
	function validateTemplateInfo(){
		var flag=false;
		var validateTemplateInfoUrl=path+"/autoMarketTempPoint/validateTempTemplate";
		$.ajax({
 			type:"post",
 			url:validateTemplateInfoUrl,
  			async: false,
  			data:{"cid" : cid,
            	"templateId":templateId
            	},success:function(data){
				if(data.status==200){
					flag=true;
				}else{
					showErrorLong(data.message);
				}
			}
		});	
		return flag;
	}
	//条件选择
	 $(".search").keyup(function() {
		 searchGoodsInfo();
        $(".table-list").show();
        $(".choicebg").hide();
    });
	var goodsArray=new Array();
	function initGoodsInfo(){
		var getNameUrl=path+"/drugScan/findPublicGoods";
		$.ajax({
			type:"post",
			url:getNameUrl,
 			async: false,
 			data:{"cid" : cid,
           	},success:function(data){
				if(data.status==200){
					goodsArray=eval(data.data);
				}/* else{
					showErrorLong("暂无药品数据");
				} */
			}
		});		
	}
	function searchGoodsInfo(){
		var keyWords=$(".search").val();
		var result = [];
		if(StringEmpty(goodsArray)){
			goodsArray.forEach(function (item, index) {
		        if (item.goodsName.includes(keyWords) || item.goodsName.includes(keyWords)) {
		            result.push(item);
		        }
		    });
			setGoodsTable(result);
		}		
	}
	function setGoodsTable(info){
		var html="";
		for(var i=0;i<info.length;i++){
			html+="<tr>";		
	        html+="<td>"+replaceUndefined(info[i].goodsName)+"</td>";
	        html+="<td>"+replaceUndefined(info[i].generalName)+"</td>";
	        html+="<td>"+replaceUndefined(info[i].specifications)+"</td>";
	      	html+="<td>"+replaceUndefined(info[i].productionCompany)+"</td>";
	  		html+="<td>"+replaceUndefined(info[i].approvalNumber)+"</td>";
			html+="<td style='border-right:none!important;'>"+replaceUndefined(info[i].goodsNumber)+"</td>";
			html+="<td style='display:none;'>"+replaceUndefined(info[i].goodsNumber)+"</td>";
			html+="</tr>";
			if(i>=9){
				break;
			}
		}		
		$("#store_trade_goods .table-list tbody").html(html);
	}
	//table表格选择
   $("#store_trade_info .table-list").off("click","tr");
	$("#store_trade_info .table-list").on("click","tr",function(){
        $(".choicebg").hide();
        var spanArray=$(".choicebg").find("span");
        var aId = $(this).index();
        if(spanArray.length>=10){
        	showError("选择药品不能超过十个");
        	return null;
        }
        if ($(this).hasClass("active")) {
            $(".item" + aId + "").remove();
            $(this).removeClass("active");
        } else {
        	 var name = $(this).children('td:eq(0)');
             var name2 = $(this).children('td:eq(1)');
             var name3 = $(this).children('td:eq(2)');
             var name4 = $(this).children('td:eq(3)');
             var name5 = $(this).children('td:eq(4)');
             var name6 = $(this).children('td:eq(5)');
             var id=$(this).children('td:eq(6)').text();
             $(this).addClass("active");
             var tactive = "tactive" + aId;
             $(this).addClass(tactive);
             var html = "<span  class='spanbg item" + aId + "' data-id='"+id+"'>";
             html += "<div class='closebg'><a class='close'><img src='<%=path%>/images/automation/close.png' height='16' width='16'></a></div>";
             html += name.text();
             html += "<table cellspacing='0' class='tablelist'>";
             html += "<thead><tr><th  width='87px'>商品名</th><th>通用名</th> <th>规格</th>";
             html += "<th width='80 px'>生产厂商</th>";
             html += "<th width='80 px'>批准文号</th><th>编码</th></tr></thead>";
             html += "<tbody><tr>";
             html += "<td>" + replaceUndefined(name.text()); + "</td>";
             html += "<td>" + replaceUndefined(name2.text()); + "</td>";
             html += "<td>" + replaceUndefined(name3.text()); + "</td>";
             html += "<td>" + replaceUndefined(name4.text()); + "</td>";
             html += "<td>" + replaceUndefined(name5.text()); + "</td>";
             html += "<td>" + replaceUndefined(name6.text()); + "</td>";
             html += "</tr> </tbody> </table>";
             html += "</span>";
             $(".choicebg").append(html);
             $(".item" + aId + "").hover(function() {
                 $(this).find("table").show();
             },function() {
                 $(this).find("table").hide();
             });
            $(".close").click(function() {
                $(this).parent().parent().remove();
                $(".tactive" + aId + "").removeClass("active");
            });
        };
    });
	//处理数据为空
	function replaceUndefined(data){
		var result="暂无";
		if(StringEmpty(data)){
			return data;
		}
		return result;
	}
    //选择列表隐藏
    $(".sure").click(function() {
        $(".table-list").hide();
        $(".choicebg").show();
    })
   $("thead>tr>th:last").css("border-right","none");  
</script>
</html>
